]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgrulesengd: Fixed processing of symlinked executables.
authorJan Safranek <jsafrane@redhat.com>
Mon, 22 Aug 2011 08:48:58 +0000 (10:48 +0200)
committerJan Safranek <jsafrane@redhat.com>
Tue, 20 Sep 2011 08:15:53 +0000 (10:15 +0200)
when an executable is symlinked and the symlink is executed,
/proc/PID/status contains name of the symlink, while /proc/PID/exe points
to the real executable name. cgrulesengd considered this case as error and
did not trigger any rule for this exec().

With this patch, cgrulesengd uses name of /proc/PID/exe as the executable
in this case.

Signed-off-by: Jan Safranek <jsafrane@redhat.com>
src/api.c

index 52d6fe70bb2f2fcd89fc3feeefde9b9089e1d795..09e6353ece198b4ae430ecacdeced342ed31e943 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -3696,11 +3696,24 @@ int cgroup_get_procname_from_procfs(pid_t pid, char **procname)
         */
        ret = cg_get_procname_from_proc_cmdline(pid, pname_status,
                                                    &pname_cmdline);
-       if (!ret)
+       if (!ret) {
                *procname = pname_cmdline;
+               free(pname_status);
+               return 0;
+       }
 
+       /*
+        * The above strncmp() is not 0 also if executing a symbolic link,
+        * /proc/pid/exe points to real executable name then.
+        * Return it as the last resort.
+        */
        free(pname_status);
-       return ret;
+       *procname = strdup(buf);
+       if (*procname == NULL) {
+               last_errno = errno;
+               return ECGOTHER;
+       }
+       return 0;
 }
 
 int cgroup_register_unchanged_process(pid_t pid, int flags)