gpiosim: get the process name using prctl()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 6 Dec 2022 13:23:54 +0000 (14:23 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 9 Dec 2022 09:06:53 +0000 (10:06 +0100)
program_invocation_short_name is set once at the program's start. If we
change the process name using prctl(), we need to retrieve it using the
same system call as program_invocation_short_name will not be updated.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
configure.ac
tests/gpiosim/gpiosim.c

index dc945efe80f3060b60306917ed8582458d3defb3..07706f0bcdea1d06663594f913f4df2746f06039 100644 (file)
@@ -85,10 +85,12 @@ AC_CHECK_FUNC([scandir], [], [FUNC_NOT_FOUND_LIB([scandir])])
 AC_CHECK_FUNC([alphasort], [], [FUNC_NOT_FOUND_LIB([alphasort])])
 AC_CHECK_FUNC([ppoll], [], [FUNC_NOT_FOUND_LIB([ppoll])])
 AC_CHECK_FUNC([realpath], [], [FUNC_NOT_FOUND_LIB([realpath])])
+AC_CHECK_FUNC([prctl], [], [FUNC_NOT_FOUND_LIB([prctl])])
 AC_CHECK_HEADERS([getopt.h], [], [HEADER_NOT_FOUND_LIB([getopt.h])])
 AC_CHECK_HEADERS([dirent.h], [], [HEADER_NOT_FOUND_LIB([dirent.h])])
 AC_CHECK_HEADERS([sys/poll.h], [], [HEADER_NOT_FOUND_LIB([sys/poll.h])])
 AC_CHECK_HEADERS([sys/sysmacros.h], [], [HEADER_NOT_FOUND_LIB([sys/sysmacros.h])])
+AC_CHECK_HEADERS([sys/prctl.h], [], [HEADER_NOT_FOUND_LIB([sys/prctl.h])])
 AC_CHECK_HEADERS([linux/version.h], [], [HEADER_NOT_FOUND_LIB([linux/version.h])])
 AC_CHECK_HEADERS([linux/const.h], [], [HEADER_NOT_FOUND_LIB([linux/const.h])])
 AC_CHECK_HEADERS([linux/ioctl.h], [], [HEADER_NOT_FOUND_LIB([linux/ioctl.h])])
index a8410f38f00075f37e18f3542bd32ce0840c0824..43d900f5110a8a3d693b01d6464f2f1444cce77d 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mount.h>
+#include <sys/prctl.h>
 #include <sys/random.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -371,11 +372,14 @@ out_unref_kmod:
 
 static char *configfs_make_item(int at, int id)
 {
-       char *item_name;
+       char *item_name, prname[17];
        int ret;
 
-       ret = asprintf(&item_name, "%s.%u.%d",
-                      program_invocation_short_name, getpid(), id);
+       ret = prctl(PR_GET_NAME, prname);
+       if (ret)
+               return NULL;
+
+       ret = asprintf(&item_name, "%s.%u.%d", prname, getpid(), id);
        if (ret < 0)
                return NULL;