vm/file-editor: wait for Xorg (and qubes-session) before starting up editor (#400)
This commit is contained in:
parent
179be85ac0
commit
aed72ca85e
@ -49,15 +49,44 @@ void send_file_back(char * filename)
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
struct stat stat_pre, stat_post;
|
struct stat stat_pre, stat_post, session_stat;
|
||||||
char *filename = get_filename();
|
char *filename = get_filename();
|
||||||
int child, status, log_fd;
|
int child, status, log_fd;
|
||||||
|
FILE *waiter_pidfile;
|
||||||
|
|
||||||
copy_file(filename);
|
copy_file(filename);
|
||||||
if (stat(filename, &stat_pre)) {
|
if (stat(filename, &stat_pre)) {
|
||||||
perror("stat pre");
|
perror("stat pre");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
// wait for X server to starts (especially in DispVM)
|
||||||
|
if (stat("/tmp/qubes-session-env", &session_stat)) {
|
||||||
|
switch (child = fork()) {
|
||||||
|
case -1:
|
||||||
|
perror("fork");
|
||||||
|
exit(1);
|
||||||
|
case 0:
|
||||||
|
waiter_pidfile = fopen("/tmp/qubes-session-waiter", "a");
|
||||||
|
if (waiter_pidfile == NULL) {
|
||||||
|
perror("fopen waiter_pidfile");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fprintf(waiter_pidfile, "%d\n", getpid());
|
||||||
|
fclose(waiter_pidfile);
|
||||||
|
// check the second time, to prevent race
|
||||||
|
if (stat("/tmp/qubes-session-env", &session_stat)) {
|
||||||
|
// wait for qubes-session notify
|
||||||
|
pause();
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
default:
|
||||||
|
waitpid(child, &status, 0);
|
||||||
|
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
|
||||||
|
//propagate exit code from child
|
||||||
|
exit(WEXITSTATUS(status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (child = fork()) {
|
switch (child = fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
perror("fork");
|
perror("fork");
|
||||||
|
Loading…
Reference in New Issue
Block a user