| 327 | } |
| 328 | |
| 329 | bool write_file(const char* file, const char* what, ...) { |
| 330 | char buf[1024]; |
| 331 | va_list args; |
| 332 | va_start(args, what); |
| 333 | vsnprintf(buf, sizeof(buf), what, args); |
| 334 | va_end(args); |
| 335 | buf[sizeof(buf) - 1] = 0; |
| 336 | int len = strlen(buf); |
| 337 | |
| 338 | int fd = open(file, O_WRONLY | O_CLOEXEC); |
| 339 | if (fd == -1) |
| 340 | return false; |
| 341 | if (write(fd, buf, len) != len) { |
| 342 | close(fd); |
| 343 | return false; |
| 344 | } |
| 345 | close(fd); |
| 346 | return true; |
| 347 | } |
| 348 | |
| 349 | void setup_sandbox() { |
| 350 | int real_uid = getuid(); |