]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (test) add a case for displaying COMMAND column
authorMasatake YAMATO <yamato@redhat.com>
Fri, 15 Oct 2021 19:24:28 +0000 (04:24 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 21 Oct 2021 12:06:39 +0000 (21:06 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/lsfd/mkfds-ro-regular-file
tests/helpers/test_mkfds.c
tests/ts/lsfd/mkfds-ro-regular-file

index f57ea5cec4e5345e8f0166d91b2d71dee51200e7..c8fef027655dda13df4820a21344cfc2c1c84297 100644 (file)
@@ -1,5 +1,5 @@
-    3  r--  REG /etc/passwd   1
-ASSOC,MODE,TYPE,NAME,POS: 0
+ABC         3  r--  REG /etc/passwd   1
+COMMAND,ASSOC,MODE,TYPE,NAME,POS: 0
 PID[RUN]: 0
 PID[STR]: 0
 INODE[RUN]: 0
index 68613cdd2571ab04d28172abeda0e0510364450b..c71b789a63316bad73e459b6e30d783188ad6103 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/prctl.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/un.h>
@@ -44,6 +45,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out, int status)
        fputs(USAGE_OPTIONS, out);
        fputs(_(" -l, --list           list available file descriptor factories and exit\n"), out);
        fputs(_(" -I, --parameters     list parameters the factory takes\n"), out);
+       fputs(_(" -r, --comm <name>    rename self\n"), out);
        fputs(_(" -q, --quiet          don't print pid(s)\n"), out);
        fputs(_(" -c, --dont-pause     don't pause after making fd(s)\n"), out);
 
@@ -583,6 +585,12 @@ static void list_parameters(const char *factory_name)
        }
 }
 
+static void rename_self(const char *comm)
+{
+       if (prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0) < 0)
+               err(EXIT_FAILURE, _("failed to rename self via prctl: %s"), comm);
+}
+
 static void do_nothing(int signum _U_)
 {
 }
@@ -602,12 +610,13 @@ int main(int argc, char **argv)
        static const struct option longopts[] = {
                { "list",       no_argument, NULL, 'l' },
                { "parameters", required_argument, NULL, 'I' },
+               { "comm",       required_argument, NULL, 'r' },
                { "quiet",      no_argument, NULL, 'q' },
                { "dont-puase", no_argument, NULL, 'c' },
                { "help",       no_argument, NULL, 'h' },
        };
 
-       while ((c = getopt_long(argc, argv, "lhqcI:", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "lhqcI:r:", longopts, NULL)) != -1) {
                switch (c) {
                case 'h':
                        usage(stdout, EXIT_SUCCESS);
@@ -623,6 +632,9 @@ int main(int argc, char **argv)
                case 'c':
                        cont = true;
                        break;
+               case 'r':
+                       rename_self(optarg);
+                       break;
                default:
                        usage(stderr, EXIT_FAILURE);
                }
index 7d991637672792edec89deede5301e0a1fb4708a..1485d74c7da807c4e579c02f969193c47263bb46 100755 (executable)
@@ -37,11 +37,11 @@ FD=3
 EXPR=
 
 {
-    coproc MKFDS { "$TS_HELPER_MKFDS" ro-regular-file $FD offset=1; }
+    coproc MKFDS { "$TS_HELPER_MKFDS" --comm ABC ro-regular-file $FD offset=1; }
     if read -u ${MKFDS[0]} PID; then
        EXPR='(PID == '"${PID}"') and (FD == '"$FD"')'
-       ${TS_CMD_LSFD} -n -o ASSOC,MODE,TYPE,NAME,POS -Q "${EXPR}"
-       echo 'ASSOC,MODE,TYPE,NAME,POS': $?
+       ${TS_CMD_LSFD} -n -o COMMAND,ASSOC,MODE,TYPE,NAME,POS -Q "${EXPR}"
+       echo 'COMMAND,ASSOC,MODE,TYPE,NAME,POS': $?
 
        LSFD_PID=$(${TS_CMD_LSFD} --raw -n -o PID -Q "${EXPR}")
        echo 'PID[RUN]:' $?