summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-06-12 16:21:45 +0200
committerSimon Rettberg2019-06-12 16:21:45 +0200
commit72dac079fbac16ea9dee6de544bdc7ed24a5e208 (patch)
treed53f1c175511f3c9bbe1343cddc8c7f2450df65d
parentMake sure user promptly sees warning when using RPC (diff)
downloadidle-daemon-72dac079fbac16ea9dee6de544bdc7ed24a5e208.tar.gz
idle-daemon-72dac079fbac16ea9dee6de544bdc7ed24a5e208.tar.xz
idle-daemon-72dac079fbac16ea9dee6de544bdc7ed24a5e208.zip
Add RPC method "warn" to show messge to users
Only usable by root.
-rw-r--r--src/main.c8
-rw-r--r--src/main.h2
-rw-r--r--src/rpc.c7
-rw-r--r--src/warn.c11
-rw-r--r--src/warn.h2
5 files changed, 27 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 81879b5..a823e03 100644
--- a/src/main.c
+++ b/src/main.c
@@ -558,3 +558,11 @@ void main_queueAction( enum Shutdown action, int delta )
}
}
+void main_warnAll( const char *message )
+{
+ for ( int idx = 0; idx < userCount; ++idx ) {
+ showWarning( &users[idx], "Warning", message );
+ }
+}
+
+
diff --git a/src/main.h b/src/main.h
index 2c792ac..b1cd420 100644
--- a/src/main.h
+++ b/src/main.h
@@ -23,4 +23,6 @@ struct user* main_getUser( const char *terminal );
void main_queueAction( enum Shutdown action, int seconds );
+void main_warnAll( const char *message );
+
#endif
diff --git a/src/rpc.c b/src/rpc.c
index a563f36..823bcca 100644
--- a/src/rpc.c
+++ b/src/rpc.c
@@ -196,6 +196,13 @@ static void handleClient( int fd, struct ucred *creds )
SENDSTRING( fd, "ok" );
}
}
+ } else if ( strncmp( buffer, "warn ", 5 ) == 0 ) {
+ if ( creds->uid != 0 ) {
+ SENDSTRING( fd, "error only root can do this" );
+ } else {
+ main_warnAll( buffer + 5 );
+ SENDSTRING( fd, "ok" );
+ }
} else {
SENDSTRING( fd, "error unknown command" );
}
diff --git a/src/warn.c b/src/warn.c
index 6dfd427..7b1ec8e 100644
--- a/src/warn.c
+++ b/src/warn.c
@@ -57,6 +57,11 @@ void warnUser( struct user *usr, enum Warning what, int seconds )
seconds %= 60;
char buffer[1000];
snprintf( buffer, sizeof(buffer), warning->message, minutes, seconds, minutes, seconds );
+ showWarning( usr, warning->title, buffer );
+}
+
+void showWarning( const struct user *usr, const char *title, const char *body )
+{
// Text or X11 warning
if ( *usr->display ) {
// notify-send
@@ -66,7 +71,7 @@ void warnUser( struct user *usr, enum Warning what, int seconds )
if ( usr->xauth[0] != '\0' && usr->xauth[0] != '-' ) {
setenv( "XAUTHORITY", usr->xauth, 1 );
}
- run( false, "notify-send", "-t", "15000", warning->title, buffer, (char*)NULL );
+ run( false, "notify-send", "-t", "15000", title, body, (char*)NULL );
}
} else {
// write to device
@@ -76,9 +81,9 @@ void warnUser( struct user *usr, enum Warning what, int seconds )
if ( fh == NULL )
return;
fputs( "\n\n****************************\n", fh );
- fputs( warning->title, fh );
+ fputs( title, fh );
fputs( "\n****************************\n", fh );
- fputs( buffer, fh );
+ fputs( body, fh );
fputs( "\n****************************\n\n", fh );
fclose( fh );
}
diff --git a/src/warn.h b/src/warn.h
index c414378..43af832 100644
--- a/src/warn.h
+++ b/src/warn.h
@@ -14,5 +14,7 @@ enum Warning
void warnUser( struct user *usr, enum Warning what, int seconds );
+void showWarning( const struct user *usr, const char *title, const char *body );
+
#endif