commit:     7a37c6318fe8d89462931590efba4a147efd08ad
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 26 15:45:26 2026 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Jan 26 15:51:28 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7a37c631

libq/xsystem: convert to 2026 codestyle

remove usage of xasprintf while at it

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/xsystem.c | 148 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 85 insertions(+), 63 deletions(-)

diff --git a/libq/xsystem.c b/libq/xsystem.c
index 17b0f24e..07290a96 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -15,76 +15,98 @@
 #include <unistd.h>
 #include <xalloc.h>
 
-#include "xasprintf.h"
 #include "xsystem.h"
 
-void xsystembash(const char *command, const char **argv, int cwd)
+void xsystembash
+(
+  const char  *command,
+  const char **argv,
+  int          cwd
+)
 {
-       pid_t p = fork();
-       int status;
+  pid_t p;
+  int   status;
 
-       switch (p) {
-               case 0: /* child */
-                       if (cwd != AT_FDCWD) {
-                               if (fchdir(cwd)) {
-                                       /* fchdir works with O_PATH starting 
w/linux-3.5 */
-                                       if (errno == EBADF) {
-                                               char *path;
-                                               xasprintf(&path, 
"/proc/self/fd/%i", cwd);
-                                               if (chdir(path))
-                                                       errp("chdir(%s) 
failed", path);
-                                       } else {
-                                               errp("fchdir(%i) failed", cwd);
-                                       }
-                               }
-                       }
-                       if (argv == NULL) {
-                               execl(CONFIG_EPREFIX "bin/bash", "bash",
-                                         "--norc", "--noprofile", "-c", 
command, (char *)NULL);
-                               /* Hrm, still here ?  Maybe no bash ... */
-                               _exit(execl("/bin/sh", "sh", "-c", command, 
(char *)NULL));
-                       } else {
-                               int          argc = 0;
-                               const char  *a;
-                               const char **newargv;
+  p = fork();
+  switch (p) {
+  case 0: /* child */
+    if (cwd != AT_FDCWD)
+    {
+      if (fchdir(cwd))
+      {
+        /* fchdir works with O_PATH starting w/linux-3.5 */
+        if (errno == EBADF)
+        {
+          char path[_Q_PATH_MAX];
+          snprintf(path, sizeof(path), "/proc/self/fd/%i", cwd);
+          if (chdir(path))
+            errp("chdir(%s) failed", path);
+        }
+        else
+        {
+          errp("fchdir(%i) failed", cwd);
+        }
+      }
+    }
+    if (argv == NULL)
+    {
+      execl(CONFIG_EPREFIX "bin/bash",
+            "bash",
+            "--norc",
+            "--noprofile",
+            "-c", command,
+            (char *)NULL);
+      /* Hrm, still here ?  Maybe no bash ... */
+      _exit(execl("/bin/sh", "sh", "-c", command, (char *)NULL));
+    }
+    else
+    {
+      int          argc = 0;
+      const char  *a;
+      const char **newargv;
 
-                               /* count existing args */
-                               for (a = argv[0]; a != NULL; a++, argc++)
-                                       ;
-                               argc += 1 + 1 + 1 + 1;
-                               newargv = xmalloc(sizeof(newargv[0]) * (argc + 
1));
-                               argc = 0;
-                               newargv[argc++] = "bash";
-                               newargv[argc++] = "--norc";
-                               newargv[argc++] = "--noprofile";
-                               newargv[argc++] = "-c";
-                               for (a = argv[0]; a != NULL; a++)
-                                       newargv[argc++] = a;
-                               newargv[argc] = NULL;
+      /* count existing args */
+      for (a = argv[0]; a != NULL; a++, argc++)
+        ;
+      argc += 1 + 1 + 1 + 1;
+      newargv = xmalloc(sizeof(newargv[0]) * (argc + 1));
+      argc = 0;
+      newargv[argc++] = "bash";
+      newargv[argc++] = "--norc";
+      newargv[argc++] = "--noprofile";
+      newargv[argc++] = "-c";
+      for (a = argv[0]; a != NULL; a++)
+        newargv[argc++] = a;
+      newargv[argc] = NULL;
 
-                               execv(CONFIG_EPREFIX "bin/bash", (char *const 
*)newargv);
+      execv(CONFIG_EPREFIX "bin/bash", (char *const *)newargv);
 
-                               /* Hrm, still here ?  Maybe no bash ... */
-                               newargv = &newargv[2];  /* shift, two args less 
*/
-                               argc = 0;
-                               newargv[argc++] = "sh";
-                               _exit(execv("/bin/sh", (char *const *)newargv));
-                       }
+      /* Hrm, still here ?  Maybe no bash ... */
+      newargv = &newargv[2];  /* shift, two args less */
+      argc = 0;
+      newargv[argc++] = "sh";
+      _exit(execv("/bin/sh", (char *const *)newargv));
+    }
 
-               default: /* parent */
-                       waitpid(p, &status, 0);
-                       if (WIFSIGNALED(status)) {
-                               err("phase crashed with signal %i: %s", 
WTERMSIG(status),
-                                       strsignal(WTERMSIG(status)));
-                       } else if (WIFEXITED(status)) {
-                               if (WEXITSTATUS(status) == 0)
-                                       return;
-                               else
-                                       err("phase exited %i", 
WEXITSTATUS(status));
-                       }
-                       /* fall through */
+  default: /* parent */
+    waitpid(p, &status, 0);
+    if (WIFSIGNALED(status))
+    {
+      err("phase crashed with signal %i: %s", WTERMSIG(status),
+          strsignal(WTERMSIG(status)));
+    }
+    else if (WIFEXITED(status))
+    {
+      if (WEXITSTATUS(status) == 0)
+        return;
+      else
+        err("phase exited %i", WEXITSTATUS(status));
+    }
+    /* fall through */
 
-               case -1: /* fucked */
-                       errp("xsystembash(%s) failed", command);
-       }
+  case -1: /* fucked */
+    errp("xsystembash(%s) failed", command);
+  }
 }
+
+/* vim: set ts=2 sw=2 expandtab cino+=\:0 foldmethod=marker: */

Reply via email to