From c9a200ca8e2dbd565549fd04dd16591ae6cacdc9 Mon Sep 17 00:00:00 2001 From: Giacomo Catenazzi Date: Wed, 19 Aug 2009 07:33:22 +0200 Subject: [PATCH] Import Debian changes 1.9.5.3-6 g15daemon (1.9.5.3-6) unstable; urgency=low * Shared devices (lcd dispaly + audio) are not good handled by udev script. Adding workaround until improving programs to handle disconnections (Closes: #541780) * Add debugging flag (and code) for init.d and udev scripts * Change syslog facility: from user to daemon * better (and more secure) screenshort creation in /tmp --- debian/changelog | 11 +++++++++++ debian/g15daemon.default | 3 +++ debian/g15daemon.init | 41 +++++++++++++++++++++++++++++++++++---- debian/g15daemon.udev | 5 ++--- g15daemon/main.c | 7 ++++--- g15daemon/utility_funcs.c | 17 ++++++++++++++-- 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index c96cd77..3c60b59 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,14 @@ +g15daemon (1.9.5.3-6) unstable; urgency=low + + * Shared devices (lcd dispaly + audio) are not good handled + by udev script. Adding workaround until improving + programs to handle disconnections (Closes: #541780) + * Add debugging flag (and code) for init.d and udev scripts + * Change syslog facility: from user to daemon + * better (and more secure) screenshort creation in /tmp + + -- Giacomo Catenazzi Wed, 19 Aug 2009 07:33:22 +0200 + g15daemon (1.9.5.3-5) unstable; urgency=low * Handle keyboard device with udev, so detecting detachement diff --git a/debian/g15daemon.default b/debian/g15daemon.default index 43e1c83..fce56c6 100644 --- a/debian/g15daemon.default +++ b/debian/g15daemon.default @@ -8,5 +8,8 @@ SWITCH_KEY="L1" +# Turn on debugging of g15 init.d and udev scripts +#G15DEBUG="on" + # Additional options that are passed to the Daemon. DAEMON_OPTS="" diff --git a/debian/g15daemon.init b/debian/g15daemon.init index bc323fa..742e328 100644 --- a/debian/g15daemon.init +++ b/debian/g15daemon.init @@ -2,8 +2,8 @@ ### BEGIN INIT INFO # Provides: g15daemon -# Required-Start: $local_fs -# Required-Stop: $local_fs +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs # Should-Start: $remote_fs # Should-Stop: $remote_fs # X-Start-Before: xdm kdm gdm ldm sdm @@ -32,6 +32,21 @@ fi set -e +if [ "$G15DEBUG" = "on" ]; then + +log() { + logger -p daemon.debug -t g15 -- "$*" +} +else + +log() { + true +} + +fi + + + wait_for_file() { local file=$1 @@ -114,17 +129,18 @@ case "$1" in echo -n "Restarting $DESC: " do_stop # the device is slow to shut-down - sleep 0.5 + sleep 1 do_start echo "$NAME." ;; udev) + log "calling g15 udev; action: $ACTION, product $PRODUCT" if [ "x$ACTION" = "xadd" ] ; then load_uinput || true wait_usr_mount || true # it seems udev will not release a device if userspace is still # connected - is_running && ( do_stop; sleep 0.5 ) + is_running && ( do_stop; sleep 1 ) do_start elif [ "x$ACTION" = "xremove" ] ; then do_stop @@ -134,6 +150,23 @@ case "$1" in fi ;; + shared-udev) + # some devices share usb also for audio, which causes some spourios + # udev messages. + log "calling g15 shared-dev; action: $ACTION, product $PRODUCT" + if [ "x$ACTION" = "xadd" ] ; then + load_uinput || true + wait_usr_mount || true + do_start + elif [ "x$ACTION" = "xremove" ] ; then + do_stop + else + echo "unknow udev action '$ACTION'" + exit 1 + + fi + ;; + *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload|udev}" >&2 diff --git a/debian/g15daemon.udev b/debian/g15daemon.udev index 81a564a..efd18ae 100644 --- a/debian/g15daemon.udev +++ b/debian/g15daemon.udev @@ -10,12 +10,11 @@ SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c225", RUN+="/etc/init.d/g15daemon u SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c222", RUN+="/etc/init.d/g15daemon udev" # Logitech G15 v2 (orange) -- extra keys and LCD -SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c227", RUN+="/etc/init.d/g15daemon udev" +SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c227", RUN+="/etc/init.d/g15daemon shared-udev" # Logitech Z10 -- extra keys and LCD SYSFS{idVendor}=="046d", SYSFS{idProduct}=="0a07", RUN+="/etc/init.d/g15daemon udev" # Logitech G15 Gamepanel -- extra keys and LCD -SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c251", RUN+="/etc/init.d/g15daemon udev" - +SYSFS{idVendor}=="046d", SYSFS{idProduct}=="c251", RUN+="/etc/init.d/g15daemon shared-udev" diff --git a/g15daemon/main.c b/g15daemon/main.c index e674475..d0189ed 100644 --- a/g15daemon/main.c +++ b/g15daemon/main.c @@ -96,10 +96,11 @@ int g15daemon_send_event(void *caller, unsigned int event, unsigned long value) displaying->backlight_state %= 3; // limit to 0-2 inclusive } if(value & G15_KEY_M1 && value & G15_KEY_M3) { +#define FILENAME_SIZE 128 static int scr_num=0; - char filename[128]; + char filename[FILENAME_SIZE]; lcd_t *displaying = lcd->masterlist->current->lcd; - sprintf(filename,"/tmp/g15daemon-sc-%i.pbm",scr_num); + snprintf(filename, FILENAME_SIZE, "/tmp/g15daemon-sc-%i.pbm",scr_num); uf_screendump_pbm(displaying->buf,filename); scr_num++; } @@ -456,7 +457,7 @@ int main (int argc, char *argv[]) struct passwd *nobody; unsigned char location[1024]; - openlog("g15daemon", LOG_PID, LOG_USER); + openlog("g15daemon", LOG_PID, LOG_DAEMON); if(strlen((char*)user)==0){ nobody = getpwnam("nobody"); }else { diff --git a/g15daemon/utility_funcs.c b/g15daemon/utility_funcs.c index c93d164..b8352da 100644 --- a/g15daemon/utility_funcs.c +++ b/g15daemon/utility_funcs.c @@ -666,12 +666,23 @@ int uf_conf_open(g15daemon_t *list, char *filename) { } int uf_screendump_pbm(unsigned char *buffer,char *filename) { + int fd; FILE *f; int x,y; #define WIDTH 40 g15canvas *canvas=g15daemon_xmalloc(sizeof(g15canvas)); memcpy(canvas->buffer,buffer,LCD_BUFSIZE); - f = fopen(filename,"w+"); + fd = open(filename, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + if(fd == -1) { + g15daemon_log(LOG_WARNING, "uf_screendump_pbm failed: open, %s.\n", strerror(errno)); + return -1; + } + f = fdopen(fd,"w"); + if(f==NULL) { + close(fd); + g15daemon_log(LOG_WARNING, "uf_screendump_pbm failed: fdopen, %s.\n", strerror(errno)); + return -1; + } fprintf(f,"P1\n160 43\n"); fprintf(f,"# G15 screendump - %s\n\n",filename); for(y=0;y<43;y++) @@ -681,7 +692,9 @@ int uf_screendump_pbm(unsigned char *buffer,char *filename) { fprintf(f,"\n"); } - fclose(f); + fclose(f); + fsync(fd); + close(fd); free(canvas); return 0; }