X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Futil.c;h=11f77abde14412f50c6032d56c3616e2444a103d;hb=e0d25329b23a43332ea340f9907721873a316f4e;hp=1babb6aed457060ed11f0e79636a29ffc4da8d84;hpb=8f2d43a0121bc9a57ba8b79b33d5ac87d36ca2f2;p=elogind.git diff --git a/src/util.c b/src/util.c index 1babb6aed..11f77abde 100644 --- a/src/util.c +++ b/src/util.c @@ -2544,7 +2544,7 @@ int ask(char *ret, const char *replies, const char *text, ...) { } } -int reset_terminal_fd(int fd) { +int reset_terminal_fd(int fd, bool switch_to_text) { struct termios termios; int r = 0; @@ -2560,7 +2560,8 @@ int reset_terminal_fd(int fd) { ioctl(fd, TIOCNXCL); /* Switch to text mode */ - ioctl(fd, KDSETMODE, KD_TEXT); + if (switch_to_text) + ioctl(fd, KDSETMODE, KD_TEXT); /* Enable console unicode mode */ ioctl(fd, KDSKBMODE, K_UNICODE); @@ -2614,7 +2615,7 @@ int reset_terminal(const char *name) { if (fd < 0) return fd; - r = reset_terminal_fd(fd); + r = reset_terminal_fd(fd, true); close_nointr_nofail(fd); return r; @@ -2808,7 +2809,8 @@ int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocst if (notify >= 0) close_nointr_nofail(notify); - if ((r = reset_terminal_fd(fd)) < 0) + r = reset_terminal_fd(fd, true); + if (r < 0) log_warning("Failed to reset terminal: %s", strerror(-r)); return fd; @@ -3261,11 +3263,15 @@ fallback: void rename_process(const char name[8]) { assert(name); - prctl(PR_SET_NAME, name); + /* This is a like a poor man's setproctitle(). It changes the + * comm field, argv[0], and also the glibc's internally used + * name of the process. For the first one a limit of 16 chars + * applies, to the second one usually one of 10 (i.e. length + * of "/sbin/init"), to the third one one of 7 (i.e. length of + * "systemd"). If you pass a longer string it will be + * truncated */ - /* This is a like a poor man's setproctitle(). The string - * passed should fit in 7 chars (i.e. the length of - * "systemd") */ + prctl(PR_SET_NAME, name); if (program_invocation_name) strncpy(program_invocation_name, name, strlen(program_invocation_name)); @@ -4617,11 +4623,12 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) { } while (!hashmap_isempty(pids)) { + pid_t pid = PTR_TO_UINT(hashmap_first_key(pids)); siginfo_t si; char *path; zero(si); - if (waitid(P_ALL, 0, &si, WEXITED) < 0) { + if (waitid(P_PID, pid, &si, WEXITED) < 0) { if (errno == EINTR) continue; @@ -5235,8 +5242,14 @@ int rtc_open(int flags) { int fd; DIR *d; - /* We open the first RTC which has hctosys=1 set. If we don't - * find any we just take the first one */ + /* First, we try to make use of the /dev/rtc symlink. If that + * doesn't exist, we open the first RTC which has hctosys=1 + * set. If we don't find any we just take the first RTC that + * exists at all. */ + + fd = open("/dev/rtc", flags); + if (fd >= 0) + return fd; d = opendir("/sys/class/rtc"); if (!d) @@ -6273,3 +6286,39 @@ void* memdup(const void *p, size_t l) { memcpy(r, p, l); return r; } + +int fd_inc_sndbuf(int fd, size_t n) { + int r, value; + socklen_t l = sizeof(value); + + r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l); + if (r >= 0 && + l == sizeof(value) && + (size_t) value >= n*2) + return 0; + + value = (int) n; + r = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)); + if (r < 0) + return -errno; + + return 1; +} + +int fd_inc_rcvbuf(int fd, size_t n) { + int r, value; + socklen_t l = sizeof(value); + + r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l); + if (r >= 0 && + l == sizeof(value) && + (size_t) value >= n*2) + return 0; + + value = (int) n; + r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)); + if (r < 0) + return -errno; + + return 1; +}