mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2025-01-22 22:48:24 +00:00
Revert "substituted the fork with a pthread"
This reverts commit 5afeaac470002d05abd56e4809bdc7fcc5fd7060. execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded. means we cannot call exec() from a thread, we must use fork. next try i'll use environment vars to pass mountpoint to forked exec.
This commit is contained in:
parent
cc9ecb9c20
commit
2751d71708
@ -26,8 +26,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
@ -75,7 +73,6 @@ int main(int argc, char **argv) {
|
||||
snprintf(mapper,255, "%s", argv[1]);
|
||||
}
|
||||
|
||||
|
||||
if(argc<3) sprintf(filename, "unknown");
|
||||
else snprintf(filename,255, "%s", argv[2]);
|
||||
|
||||
@ -135,7 +132,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
notify_uninit();
|
||||
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
||||
@ -162,42 +158,29 @@ gboolean cb_view(GtkWidget *w, GdkEvent *e) {
|
||||
return FALSE;
|
||||
}
|
||||
if (cpid == 0) { // Child
|
||||
execlp("tomb-open", "tomb-open", "-q", mountpoint ,(char*)NULL);
|
||||
execlp("tomb-open", "tomb-open", mountpoint ,(char*)NULL);
|
||||
exit(1);
|
||||
}
|
||||
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) {
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
int *res;
|
||||
|
||||
if(pthread_attr_init (&attr) == -1) {
|
||||
fprintf(stderr, "error initializing POSIX thread attribute\n");
|
||||
pid_t cpid = fork();
|
||||
int res;
|
||||
if (cpid == -1) {
|
||||
fprintf(stderr,"error: problem forking process\n");
|
||||
return FALSE;
|
||||
}
|
||||
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
pthread_create(&thread, &attr, thread_close, mapper);
|
||||
|
||||
pthread_join(thread,(void**)&res);
|
||||
|
||||
if(*res==0) {
|
||||
pthread_attr_destroy(&attr);
|
||||
if (cpid == 0) { // Child
|
||||
execlp("tomb", "tomb", "close", mapper, (char*)NULL);
|
||||
exit(1);
|
||||
}
|
||||
waitpid(cpid, &res, 0);
|
||||
if(res==0) {
|
||||
gtk_main_quit();
|
||||
notify_uninit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user