[PATCH] adjust showfiles.c to new signal semantic

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] adjust showfiles.c to new signal semantic

Lino Sanfilippo



Hi,

this patch adjusts the test program (showfiles.c) to the new signal
semantic that is used by dazukofs.
Without this the program may not be interruptable by SIGINT, SIGTERM and
SIGHUP
(depending on the underlaying signal() call implementation).

It simply removes the unportable signal() with the portable sigaction()
function.
It applies against dazukofs-3.1.4-rc3.

Regards,
Lino


Geschäftsführender Gesellschafter: Tjark Auerbach
Sitz der Gesellschaft: Tettnang
Handelsregister: Amtsgericht Ulm, HRB 630992
ALLGEMEINE GESCHÄFTSBEDINGUNGEN
Es gelten unsere Allgemeinen Geschäftsbedingungen
(AGB). Sie finden sie in der jeweils gültigen Fassung
im Internet unter http://www.avira.com/de/standard-terms-conditions-business-de
***************************************************

diff -Nurp dazukofs-3.1.4-rc3/test/showfiles.c dazukofs-3.1.4-rc3-PATCH1/test/showfiles.c
--- dazukofs-3.1.4-rc3/test/showfiles.c 2008-10-25 00:08:30.000000000 +0200
+++ dazukofs-3.1.4-rc3-PATCH1/test/showfiles.c 2010-11-12 13:26:26.000000000 +0100
@@ -25,7 +25,7 @@
 #include <errno.h>
 #include <signal.h>
 
-static int running = 1;
+static volatile sig_atomic_t running = 1;
 
 static void print_access(struct dazukofs_access *acc)
 {
@@ -48,12 +48,26 @@ static void sigterm(int sig)
 
 int main(void)
 {
+ struct sigaction sa;
  dazukofs_handle_t hndl;
  struct dazukofs_access acc;
 
- signal(SIGHUP, sigterm);
- signal(SIGINT, sigterm);
- signal(SIGTERM, sigterm);
+ memset(&sa, 0, sizeof(sa));
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = sigterm;
+ if (sigaction(SIGHUP, &sa, NULL)) {
+ perror("install SIGHUP handler");
+ return -1;
+ }
+ if (sigaction(SIGINT, &sa, NULL)) {
+ perror("install SIGINT handler");
+ return -1;
+ }
+ if (sigaction(SIGTERM, &sa, NULL)) {
+ perror("install SIGTERM handler");
+ return -1;
+ }
 
  hndl = dazukofs_open("dazukofs_example", DAZUKOFS_TRACK_GROUP);
  if (!hndl) {

_______________________________________________
Dazuko-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/dazuko-devel