From: Masatake YAMATO Date: Fri, 15 Oct 2021 19:24:28 +0000 (+0900) Subject: lsfd: (test) add a case for displaying COMMAND column X-Git-Tag: v2.38-rc1~144^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=863a6544c32323157b900e81bf6b4a6da9e712dc;p=thirdparty%2Futil-linux.git lsfd: (test) add a case for displaying COMMAND column Signed-off-by: Masatake YAMATO --- diff --git a/tests/expected/lsfd/mkfds-ro-regular-file b/tests/expected/lsfd/mkfds-ro-regular-file index f57ea5cec4..c8fef02765 100644 --- a/tests/expected/lsfd/mkfds-ro-regular-file +++ b/tests/expected/lsfd/mkfds-ro-regular-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 diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 68613cdd25..c71b789a63 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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 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); } diff --git a/tests/ts/lsfd/mkfds-ro-regular-file b/tests/ts/lsfd/mkfds-ro-regular-file index 7d99163767..1485d74c7d 100755 --- a/tests/ts/lsfd/mkfds-ro-regular-file +++ b/tests/ts/lsfd/mkfds-ro-regular-file @@ -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]:' $?