Obsolete VTE pre-2.91 ABI
[oi-userland.git] / components / desktop / lightdm / patches / 13-save-audio-settings.patch
blob2571e6410ee6afa64d81f9d2c7cbe8a86b050807
1 --- lightdm-1.19.3/src/session-child.c.~6~ 2016-08-12 20:29:20.896781907 +0300
2 +++ lightdm-1.19.3/src/session-child.c 2016-08-12 20:34:18.800499967 +0300
3 @@ -17,6 +17,7 @@
4 #include <utmp.h>
5 #include <utmpx.h>
6 #include <sys/mman.h>
7 +#include <sys/soundcard.h>
9 #if HAVE_LIBAUDIT
10 #include <libaudit.h>
11 @@ -32,6 +33,8 @@
12 #include "x-authority.h"
13 #include "configuration.h"
15 +#define MAX_HOSTNAME 256
17 /* Child process being run */
18 static GPid child_pid = 0;
20 @@ -113,6 +113,82 @@
21 privileges_reclaim ();
24 +/*
25 + /usr/bin/audioctl save-controls -d $AUDIOCTL_SAVE_DEVICE \
26 + -f $AUDIOCTL_SAVE_DIR/audioctl-$AUDIOCTL_SAVE_HOSTNAME-$AUDIOCTL_SAVE_DEVICE
27 +*/
28 +#define AUDIO_SETTINGS_SAVE "/usr/bin/audioctl save-controls -d %s -f \"%s/audioctl-%s-%s\""
30 +static void
31 +save_audio_settings(User *user)
33 + char hostname[MAX_HOSTNAME];
34 + char *user_name,*save_dir;
35 + struct passwd *pwd;
36 + struct stat st,st_sd;
38 + if(gethostname(hostname,MAX_HOSTNAME))
39 + return;
41 + user_name=user_get_name(user);
42 + pwd=getpwnam(user_name);
43 + if(pwd == NULL || pwd->pw_dir == NULL)
44 + return;
46 + if(stat("/dev/audio", &st))
47 + return;
49 + if(st.st_uid == user_get_uid(user)) {
50 + gboolean drop_privileges;
51 + int fd=-1, i;
52 + oss_sysinfo si;
54 + drop_privileges = geteuid () == 0;
55 + if (drop_privileges)
56 + privileges_drop (user_get_uid (user), user_get_gid (user));
58 + save_dir=g_strdup_printf("%s/.audioctl", pwd->pw_dir);
59 + if (!save_dir)
60 + return;
62 + if(stat(save_dir, &st_sd)) {
63 + if(mkdir(save_dir, S_IRWXU)){
64 + g_free(save_dir);
65 + return;
66 + }
67 + }
69 + if ((fd = open("/dev/mixer", O_RDWR)) < 0){
70 + g_free(save_dir);
71 + return;
72 + }
74 + if (ioctl(fd, SNDCTL_SYSINFO, &si) < 0) {
75 + g_free(save_dir);
76 + return;
77 + }
79 + for (i = 0; i < si.nummixers; i++) {
80 + struct stat sbuf;
81 + oss_mixerinfo mixer;
82 + char *command;
84 + mixer.dev = i;
85 + if (ioctl(fd, SNDCTL_MIXERINFO, &mixer) != 0)
86 + continue;
88 + command=g_strdup_printf(AUDIO_SETTINGS_SAVE, mixer.name, save_dir, hostname, mixer.name);
89 + system(command);
90 + g_free(command);
91 + }
93 + if (drop_privileges)
94 + privileges_reclaim ();
96 + }
97 + g_free(save_dir);
100 static gchar *
101 read_string (void)
103 @@ -827,6 +827,9 @@
105 run_linc_cleanup(user);
107 + if (g_strcmp0 (pam_getenv (pam_handle, "XDG_SESSION_CLASS"), "greeter") != 0)
108 + save_audio_settings(user);
110 if (!remote_host_name && !g_strcmp0(xdisplay,":0") && (g_str_has_prefix (tty, "/dev/vt/") || !g_strcmp0(tty,"/dev/console"))){
111 di_devperm_logout (tty);