summaryrefslogtreecommitdiff
path: root/sway/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/sway/main.c b/sway/main.c
index e960c4e2..b6f8a8bf 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -27,6 +28,7 @@
static bool terminate_request = false;
static int exit_value = 0;
+static struct rlimit original_nofile_rlimit = {0};
struct sway_server server = {0};
struct sway_debug debug = {0};
@@ -63,7 +65,7 @@ void detect_proprietary(int allow_unsupported_gpu) {
sway_log(SWAY_ERROR,
"Proprietary Nvidia drivers are NOT supported. "
"Use Nouveau. To launch sway anyway, launch with "
- "--my-next-gpu-wont-be-nvidia and DO NOT report issues.");
+ "--unsupported-gpu and DO NOT report issues.");
exit(EXIT_FAILURE);
}
break;
@@ -151,6 +153,9 @@ static void log_kernel(void) {
static bool drop_permissions(void) {
if (getuid() != geteuid() || getgid() != getegid()) {
+ sway_log(SWAY_ERROR, "!!! DEPRECATION WARNING: "
+ "SUID privilege drop will be removed in a future release, please migrate to seatd-launch");
+
// Set the gid and uid in the correct order.
if (setgid(getgid()) != 0) {
sway_log(SWAY_ERROR, "Unable to drop root group, refusing to start");
@@ -169,6 +174,33 @@ static bool drop_permissions(void) {
return true;
}
+static void increase_nofile_limit(void) {
+ if (getrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) {
+ sway_log_errno(SWAY_ERROR, "Failed to bump max open files limit: "
+ "getrlimit(NOFILE) failed");
+ return;
+ }
+
+ struct rlimit new_rlimit = original_nofile_rlimit;
+ new_rlimit.rlim_cur = new_rlimit.rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, &new_rlimit) != 0) {
+ sway_log_errno(SWAY_ERROR, "Failed to bump max open files limit: "
+ "setrlimit(NOFILE) failed");
+ sway_log(SWAY_INFO, "Running with %d max open files",
+ (int)original_nofile_rlimit.rlim_cur);
+ }
+}
+
+void restore_nofile_limit(void) {
+ if (original_nofile_rlimit.rlim_cur == 0) {
+ return;
+ }
+ if (setrlimit(RLIMIT_NOFILE, &original_nofile_rlimit) != 0) {
+ sway_log_errno(SWAY_ERROR, "Failed to restore max open files limit: "
+ "setrlimit(NOFILE) failed");
+ }
+}
+
void enable_debug_flag(const char *flag) {
if (strcmp(flag, "damage=highlight") == 0) {
debug.damage = DAMAGE_HIGHLIGHT;
@@ -220,7 +252,6 @@ int main(int argc, char **argv) {
{"verbose", no_argument, NULL, 'V'},
{"get-socketpath", no_argument, NULL, 'p'},
{"unsupported-gpu", no_argument, NULL, 'u'},
- {"my-next-gpu-wont-be-nvidia", no_argument, NULL, 'u'},
{0, 0, 0, 0}
};
@@ -314,7 +345,6 @@ int main(int argc, char **argv) {
log_kernel();
log_distro();
log_env();
- detect_proprietary(allow_unsupported_gpu);
if (optind < argc) { // Behave as IPC client
if (optind != 1) {
@@ -341,6 +371,8 @@ int main(int argc, char **argv) {
return 0;
}
+ detect_proprietary(allow_unsupported_gpu);
+
if (!server_privileged_prepare(&server)) {
return 1;
}
@@ -350,6 +382,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ increase_nofile_limit();
+
// handle SIGTERM signals
signal(SIGTERM, sig_handler);
signal(SIGINT, sig_handler);