2014-07-26 14:31:44 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s [n|y]\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
mode_t mode;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
usage();
|
|
|
|
|
2014-11-30 13:12:15 +00:00
|
|
|
if (isatty(2) == 0)
|
2014-08-04 20:02:28 +00:00
|
|
|
eprintf("stderr: not a tty\n");
|
2014-07-26 14:31:44 +00:00
|
|
|
|
2014-11-30 13:12:15 +00:00
|
|
|
if (fstat(2, &sb) < 0)
|
2014-08-04 20:02:28 +00:00
|
|
|
eprintf("fstat stderr:");
|
2014-07-26 14:31:44 +00:00
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
puts(sb.st_mode & (S_IWGRP | S_IWOTH) ? "is y" : "is n");
|
2014-10-02 22:45:25 +00:00
|
|
|
return 0;
|
2014-07-26 14:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 14:51:21 +00:00
|
|
|
if (argv[0][0] == 'y' && argv[0][1] == '\0')
|
2014-07-26 14:31:44 +00:00
|
|
|
mode = sb.st_mode | S_IWGRP | S_IWOTH;
|
2014-07-26 14:51:21 +00:00
|
|
|
else if (argv[0][0] == 'n' && argv[0][1] == '\0')
|
2014-07-26 14:31:44 +00:00
|
|
|
mode = sb.st_mode & ~(S_IWGRP | S_IWOTH);
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
|
2014-11-30 13:12:15 +00:00
|
|
|
if (fchmod(2, mode) < 0)
|
2014-08-04 20:02:28 +00:00
|
|
|
eprintf("fchmod stderr:");
|
2014-07-26 14:31:44 +00:00
|
|
|
|
2014-10-02 22:45:25 +00:00
|
|
|
return 0;
|
2014-07-26 14:31:44 +00:00
|
|
|
}
|