~ubuntu-branches/ubuntu/wily/aegisub/wily-proposed

« back to all changes in this revision

Viewing changes to tools/osx-bundle-restart-helper.m

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel, Pascal De Vuyst, Juan Picca, Sebastian Reichel
  • Date: 2015-08-04 21:40:50 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150804214050-y2aghm9vdksoc8t7
Tags: 3.2.2+dfsg-1
[ Pascal De Vuyst ]
* Fix Typo in package description (Closes: #739219)

[ Juan Picca ]
* Add patch to fix reproducible build (Closes: #789728)

[ Sebastian Reichel ]
* New upstream release
 - remove vendor directory from orig tarball
* Update Debian Standards Version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2009 Niels Martin Hansen
 
3
 
 
4
  Redistribution and use in source and binary forms, with or without
 
5
  modification, are permitted provided that the following conditions are met:
 
6
 
 
7
  * Redistributions of source code must retain the above copyright notice,
 
8
    this list of conditions and the following disclaimer.
 
9
  * Redistributions in binary form must reproduce the above copyright notice,
 
10
    this list of conditions and the following disclaimer in the documentation
 
11
    and/or other materials provided with the distribution.
 
12
  * Neither the name of the Aegisub Group nor the names of its contributors
 
13
    may be used to endorse or promote products derived from this software
 
14
    without specific prior written permission.
 
15
 
 
16
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
17
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
18
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
19
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
20
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
21
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
22
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
23
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
24
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
25
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
26
  POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
#include <stdlib.h>
 
30
#include <unistd.h>
 
31
#include <stdio.h>
 
32
#include <sys/types.h>
 
33
#include <sys/event.h>
 
34
#include <sys/time.h>
 
35
 
 
36
@import Foundation;
 
37
 
 
38
/*
 
39
Return codes:
 
40
1: Error in kqueue()
 
41
2: Error in kevent()
 
42
3: Timed out waiting for parent to exit
 
43
4: Error in execve()
 
44
 
 
45
If none of those happen the requested command is execve()'d.
 
46
*/
 
47
int main(int argc, char *argv[], char *env[]) {
 
48
        int queue = kqueue();
 
49
        if (queue  == -1) {
 
50
                perror("Error in: kqueue()");
 
51
                return 1;
 
52
        }
 
53
 
 
54
        struct kevent event[1];
 
55
        EV_SET(event,
 
56
               getppid(),
 
57
               EVFILT_PROC,
 
58
               EV_ADD|EV_ENABLE|EV_ONESHOT,
 
59
               NOTE_EXIT,
 
60
               0, 0);
 
61
 
 
62
        printf("restart-helper: waiting for pid %d\n", getppid());
 
63
 
 
64
        struct kevent change[1];
 
65
        struct timespec timeout = { 30, 0 };
 
66
        int nchange = kevent(queue, change, 1, event, 1, &timeout);
 
67
 
 
68
        if (nchange < 0) {
 
69
                perror("restart-helper: Error in kevent()");
 
70
                return 2;
 
71
        }
 
72
        if (nchange == 0) {
 
73
                printf("restart-helper: Timed out waiting for pid %d\n", getppid());
 
74
                return 3;
 
75
        }
 
76
        if (change[0].flags & EV_ERROR) {
 
77
                perror("restart-helper: Error in event");
 
78
                return 2;
 
79
        }
 
80
 
 
81
        close(queue);
 
82
 
 
83
        printf("restart-helper: Executing '%s'\n", argv[1]);
 
84
 
 
85
        @try {
 
86
                [NSTask launchedTaskWithLaunchPath:[NSString stringWithUTF8String:argv[1]] arguments:@[]];
 
87
        }
 
88
        @catch (NSException *e) {
 
89
                printf("restart-helper: Error launching program: %s\n", e.description.UTF8String);
 
90
                return 4;
 
91
        }
 
92
 
 
93
        return 0;
 
94
}