Skip to content

Commit

Permalink
uptime: Use pledge()
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 18, 2020
1 parent 3b3b4b0 commit b2f9a60
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Userland/uptime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@
*/

#include <stdio.h>
#include <unistd.h>

int main(int, char**)
{
if (pledge("stdio rpath", nullptr) < 0) {
perror("pledge");
return 1;
}

FILE* fp = fopen("/proc/uptime", "r");
if (!fp) {
perror("fopen(/proc/uptime)");
return 1;
}

if (pledge("stdio", nullptr) < 0) {
perror("pledge");
return 1;
}

char buffer[BUFSIZ];
auto* p = fgets(buffer, sizeof(buffer), fp);
if (!p) {
Expand Down

0 comments on commit b2f9a60

Please sign in to comment.