add pledge support and error messages

This commit is contained in:
bch 2017-02-18 21:12:30 +00:00
parent 4152e1651f
commit 39f3aa2ab6

15
xmem.c
View File

@ -7,8 +7,10 @@
* $XConsortium: xload.c,v 1.36 91/05/24 16:57:46 converse Exp $
*/
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <err.h>
#include <errno.h>
#include <X11/Intrinsic.h>
#include <X11/Xatom.h>
#include <X11/StringDefs.h>
@ -157,8 +159,10 @@ int main(int argc, char **argv)
/* For security reasons, we reset our uid/gid after doing the necessary
system initialization and before calling any X routines. */
setgid(getgid()); /* reset gid first while still (maybe) root */
setuid(getuid());
if (setgid(getgid()) == -1)
errx(1, "%s: setgid failed: %s\n", argv[0], strerror(errno));
if (setuid(getuid()) == -1)
errx(1, "%s: setuid failed: %s\n", argv[0], strerror(errno));
toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem),
&argc, argv, NULL, NULL, (Cardinal) 0);
@ -218,7 +222,10 @@ int main(int argc, char **argv)
False);
(void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
&wm_delete_window, 1);
if (pledge("ps vminfo stdio", NULL) == -1)
errx(1, "pledge failed: %s", strerror(errno));
XtAppMainLoop(app_con);
}