mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-09 22:50:56 +00:00
substituted the fork with a pthread
fixes a bug in closing tombs from the status tray icon
This commit is contained in:
parent
617b996865
commit
5afeaac470
@ -26,6 +26,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <libnotify/notify.h>
|
#include <libnotify/notify.h>
|
||||||
|
|
||||||
@ -73,6 +75,7 @@ int main(int argc, char **argv) {
|
|||||||
snprintf(mapper,255, "%s", argv[1]);
|
snprintf(mapper,255, "%s", argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(argc<3) sprintf(filename, "unknown");
|
if(argc<3) sprintf(filename, "unknown");
|
||||||
else snprintf(filename,255, "%s", argv[2]);
|
else snprintf(filename,255, "%s", argv[2]);
|
||||||
|
|
||||||
@ -132,6 +135,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
notify_uninit();
|
notify_uninit();
|
||||||
|
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -158,29 +162,42 @@ gboolean cb_view(GtkWidget *w, GdkEvent *e) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (cpid == 0) { // Child
|
if (cpid == 0) { // Child
|
||||||
execlp("tomb-open", "tomb-open", mountpoint ,(char*)NULL);
|
execlp("tomb-open", "tomb-open", "-q", mountpoint ,(char*)NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* thread_close(void *arg) {
|
||||||
|
char *map = (char*)arg;
|
||||||
|
execlp("tomb", "tomb", "-q", "close", map, (char*)NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean cb_close(GtkWidget *w, GdkEvent *e) {
|
gboolean cb_close(GtkWidget *w, GdkEvent *e) {
|
||||||
pid_t cpid = fork();
|
pthread_t thread;
|
||||||
int res;
|
pthread_attr_t attr;
|
||||||
if (cpid == -1) {
|
int *res;
|
||||||
fprintf(stderr,"error: problem forking process\n");
|
|
||||||
|
if(pthread_attr_init (&attr) == -1) {
|
||||||
|
fprintf(stderr, "error initializing POSIX thread attribute\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (cpid == 0) { // Child
|
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
|
||||||
execlp("tomb", "tomb", "close", mapper, (char*)NULL);
|
|
||||||
exit(1);
|
pthread_create(&thread, &attr, thread_close, mapper);
|
||||||
}
|
|
||||||
waitpid(cpid, &res, 0);
|
pthread_join(thread,(void**)&res);
|
||||||
if(res==0) {
|
|
||||||
|
if(*res==0) {
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
notify_uninit();
|
notify_uninit();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user