- if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
- die("cannot disable the out-of-memory killer for this process\n");
+
+ /* convert OOM_SCORE_ADJ_MIN to string for writing */
+ length = snprintf(value, sizeof(value), "%d\n", OOM_SCORE_ADJ_MIN);
+
+ /* bail on truncation */
+ if (length >= sizeof(value))
+ die("buffer too small\n");
+
+ if (fd < 0 || write(fd, value, length) != length || close(fd) != 0)
+ die("cannot disable the out-of-memory killer for this process (make sure to suid or sgid slock)\n");