Browse Source

explicitely ignore return value of symlink(3) call

glibc sets __attribute_warn_unused_result__ on symlink(3) if
FORTIFY_SOURCE is set. This breaks procd which deliberately ignores
the result of the symlink(3) call early during init as there wouldn't
be anything better to do in that case other than ignoring the error and
trying to survive.

Introduce libc-compat.h to work-around libc anomalities.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Daniel Golle 5 years ago
parent
commit
d5fddd91b9
3 changed files with 14 additions and 2 deletions
  1. 2 1
      initd/early.c
  2. 10 0
      libc-compat.h
  3. 2 1
      plug/coldplug.c

+ 2 - 1
initd/early.c

@@ -22,6 +22,7 @@
 #include <stdlib.h>
 
 #include "init.h"
+#include "../libc-compat.h"
 
 static void
 early_dev(void)
@@ -66,7 +67,7 @@ early_mounts(void)
 	mount("sysfs", "/sys", "sysfs", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
 	mount("cgroup", "/sys/fs/cgroup", "cgroup",  MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
 	mount("tmpfs", "/dev", "tmpfs", MS_NOATIME | MS_NOSUID, "mode=0755,size=512K");
-	symlink("/tmp/shm", "/dev/shm");
+	ignore(symlink("/tmp/shm", "/dev/shm"));
 	mkdir("/dev/pts", 0755);
 	mount("devpts", "/dev/pts", "devpts", MS_NOATIME | MS_NOEXEC | MS_NOSUID, "mode=600");
 	early_dev();

+ 10 - 0
libc-compat.h

@@ -0,0 +1,10 @@
+#ifndef __PROCD_LIBC_COMPAT_H
+#define __PROCD_LIBC_COMPAT_H
+
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+static inline int ignore(int x) {return x;}
+#else
+#define ignore(x) x
+#endif
+
+#endif

+ 2 - 1
plug/coldplug.c

@@ -19,6 +19,7 @@
 #include <unistd.h>
 
 #include "../procd.h"
+#include "../libc-compat.h"
 
 #include "hotplug.h"
 
@@ -45,7 +46,7 @@ void procd_coldplug(void)
 	umount2("/dev/pts", MNT_DETACH);
 	umount2("/dev/", MNT_DETACH);
 	mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755,size=512K");
-	symlink("/tmp/shm", "/dev/shm");
+	ignore(symlink("/tmp/shm", "/dev/shm"));
 	mkdir("/dev/pts", 0755);
 	umask(oldumask);
 	mount("devpts", "/dev/pts", "devpts", MS_NOEXEC | MS_NOSUID, 0);