~ted/ubuntu-app-launch/snap-icon-unbreak

« back to all changes in this revision

Viewing changes to desktop-single.c

Updated to failure-is-an-option

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as published
6
 
 * by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authors:
17
 
 *     Ted Gould <ted.gould@canonical.com>
18
 
 */
19
 
 
20
 
#include "helpers.h"
21
 
#include "desktop-single-trace.h"
22
 
 
23
 
int
24
 
main (int argc, char * argv[])
25
 
{
26
 
        /* Nothing is single instance yet */
27
 
        if (argc != 2) {
28
 
                g_error("Should be called as: %s <app_id>", argv[0]);
29
 
                return 1;
30
 
        }
31
 
 
32
 
        g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */
33
 
        tracepoint(upstart_app_launch, desktop_single_start);
34
 
 
35
 
        GKeyFile * keyfile = keyfile_for_appid(argv[1], NULL);
36
 
 
37
 
        if (keyfile == NULL) {
38
 
                g_error("Unable to find keyfile for application '%s'", argv[0]);
39
 
                return 1;
40
 
        }
41
 
 
42
 
        tracepoint(upstart_app_launch, desktop_single_found);
43
 
 
44
 
        gboolean singleinstance = FALSE;
45
 
 
46
 
        if (g_key_file_has_key(keyfile, "Desktop Entry", "X-Ubuntu-Single-Instance", NULL)) {
47
 
                GError * error = NULL;
48
 
 
49
 
                singleinstance = g_key_file_get_boolean(keyfile, "Desktop Entry", "X-Ubuntu-Single-Instance", &error);
50
 
 
51
 
                if (error != NULL) {
52
 
                        g_warning("Unable to get single instance key for app '%s': %s", argv[1], error->message);
53
 
                        g_error_free(error);
54
 
                        /* Ensure that if we got an error, we assume standard case */
55
 
                        singleinstance = FALSE;
56
 
                }
57
 
        }
58
 
        
59
 
        g_key_file_free(keyfile);
60
 
 
61
 
        tracepoint(upstart_app_launch, desktop_single_finished);
62
 
 
63
 
        if (singleinstance) {
64
 
                return 0;
65
 
        } else {
66
 
                return 1;
67
 
        }
68
 
}