]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: move proctitle code to login.c
authorKarel Zak <kzak@redhat.com>
Tue, 6 Oct 2020 13:13:29 +0000 (15:13 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Oct 2020 13:15:15 +0000 (15:15 +0200)
The functions are used only by login(1), let's keep the code in
login.c only.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/Makemodule.am
include/setproctitle.h [deleted file]
lib/Makemodule.am
lib/setproctitle.c [deleted file]
login-utils/login.c

index e6d3f3ed67481fd94627a0a6cebd5b5fbf72a8c4..8d40fa48201a1cad6f598716c1441140a22e62a5 100644 (file)
@@ -57,7 +57,6 @@ dist_noinst_HEADERS += \
        include/rpmatch.h \
        include/sha1.h \
        include/signames.h \
-       include/setproctitle.h \
        include/statfs_magic.h \
        include/strutils.h \
        include/strv.h \
diff --git a/include/setproctitle.h b/include/setproctitle.h
deleted file mode 100644 (file)
index 70a9efa..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef UTIL_LINUX_SETPROCTITLE_H
-#define UTIL_LINUX_SETPROCTITLE_H
-
-extern void initproctitle (int argc, char **argv);
-extern void setproctitle (const char *prog, const char *txt);
-
-#endif
index 2548e60fead5c2f9a2dab16d666251f595be18ab..e2e3e4f7c6d76eb3eac4cfb6a6f00c028c467ab8 100644 (file)
@@ -31,7 +31,6 @@ libcommon_la_SOURCES = \
        lib/procutils.c \
        lib/pwdutils.c \
        lib/randutils.c \
-       lib/setproctitle.c \
        lib/strutils.c \
        lib/timeutils.c \
        lib/ttyutils.c \
diff --git a/lib/setproctitle.c b/lib/setproctitle.c
deleted file mode 100644 (file)
index 7168e46..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  set process title for ps (from sendmail)
- *
- *  Clobbers argv of our main procedure so ps(1) will display the title.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "setproctitle.h"
-
-#ifndef SPT_BUFSIZE
-# define SPT_BUFSIZE     2048
-#endif
-
-extern char **environ;
-
-static char **argv0;
-static size_t argv_lth;
-
-void initproctitle (int argc, char **argv)
-{
-       int i;
-       char **envp = environ;
-
-       /*
-        * Move the environment so we can reuse the memory.
-        * (Code borrowed from sendmail.)
-        * WARNING: ugly assumptions on memory layout here;
-        *          if this ever causes problems, #undef DO_PS_FIDDLING
-        */
-       for (i = 0; envp[i] != NULL; i++)
-               continue;
-
-       environ = malloc(sizeof(char *) * (i + 1));
-       if (environ == NULL)
-               return;
-
-       for (i = 0; envp[i] != NULL; i++)
-               if ((environ[i] = strdup(envp[i])) == NULL)
-                       return;
-       environ[i] = NULL;
-
-       if (i > 0)
-               argv_lth = envp[i-1] + strlen(envp[i-1]) - argv[0];
-       else
-               argv_lth = argv[argc-1] + strlen(argv[argc-1]) - argv[0];
-       if (argv_lth > 1)
-               argv0 = argv;
-}
-
-void setproctitle (const char *prog, const char *txt)
-{
-        size_t i;
-        char buf[SPT_BUFSIZE];
-
-        if (!argv0)
-                return;
-
-       if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE)
-               return;
-
-       sprintf(buf, "%s -- %s", prog, txt);
-
-        i = strlen(buf);
-        if (i > argv_lth - 2) {
-                i = argv_lth - 2;
-                buf[i] = '\0';
-        }
-       memset(argv0[0], '\0', argv_lth);       /* clear the memory area */
-        strcpy(argv0[0], buf);
-
-        argv0[1] = NULL;
-}
index 5c1f03fa225c4e0a0aa09949d03e540557a9f26a..5cd77acf4ba4e20b097adb6e0defa3021a47ad86 100644 (file)
@@ -68,7 +68,6 @@
 #endif
 
 #include "c.h"
-#include "setproctitle.h"
 #include "pathnames.h"
 #include "strutils.h"
 #include "nls.h"
 # define TTY_MODE 0600
 #endif
 
+#ifndef SPT_BUFSIZE
+# define SPT_BUFSIZE     2048
+#endif
+
+static char **argv0;
+static size_t argv_lth;
+
 #define        TTYGRPNAME      "tty"   /* name of group to own ttys */
 #define VCS_PATH_MAX   64
 
@@ -166,7 +172,6 @@ static int is_consoletty(int fd)
 }
 #endif
 
-
 /*
  * Robert Ambrose writes:
  * A couple of my users have a problem with login processes hanging around
@@ -226,6 +231,61 @@ static void __attribute__ ((__noreturn__)) sleepexit(int eval)
        exit(eval);
 }
 
+static void process_title_init (int argc, char **argv)
+{
+       int i;
+       char **envp = environ;
+
+       /*
+        * Move the environment so we can reuse the memory.
+        * (Code borrowed from sendmail.)
+        * WARNING: ugly assumptions on memory layout here;
+        *          if this ever causes problems, #undef DO_PS_FIDDLING
+        */
+       for (i = 0; envp[i] != NULL; i++)
+               continue;
+
+       environ = malloc(sizeof(char *) * (i + 1));
+       if (environ == NULL)
+               return;
+
+       for (i = 0; envp[i] != NULL; i++)
+               if ((environ[i] = strdup(envp[i])) == NULL)
+                       return;
+       environ[i] = NULL;
+
+       if (i > 0)
+               argv_lth = envp[i-1] + strlen(envp[i-1]) - argv[0];
+       else
+               argv_lth = argv[argc-1] + strlen(argv[argc-1]) - argv[0];
+       if (argv_lth > 1)
+               argv0 = argv;
+}
+
+static void process_title_update (const char *prog, const char *txt)
+{
+        size_t i;
+        char buf[SPT_BUFSIZE];
+
+        if (!argv0)
+                return;
+
+       if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE)
+               return;
+
+       sprintf(buf, "%s -- %s", prog, txt);
+
+        i = strlen(buf);
+        if (i > argv_lth - 2) {
+                i = argv_lth - 2;
+                buf[i] = '\0';
+        }
+       memset(argv0[0], '\0', argv_lth);       /* clear the memory area */
+        strcpy(argv0[0], buf);
+
+        argv0[1] = NULL;
+}
+
 static const char *get_thishost(struct login_context *cxt, const char **domain)
 {
        if (!cxt->thishost) {
@@ -1245,7 +1305,7 @@ int main(int argc, char **argv)
        signal(SIGINT, SIG_IGN);
 
        setpriority(PRIO_PROCESS, 0, 0);
-       initproctitle(argc, argv);
+       process_title_init(argc, argv);
 
        while ((c = getopt_long(argc, argv, "fHh:pV", longopts, NULL)) != -1)
                switch (c) {
@@ -1375,7 +1435,7 @@ int main(int argc, char **argv)
 
        init_environ(&cxt);             /* init $HOME, $TERM ... */
 
-       setproctitle("login", cxt.username);
+       process_title_update("login", cxt.username);
 
        log_syslog(&cxt);