Check for overflow when allocating RcBox
[glib.git] / gio / gio-launch-desktop.c
blob03845df28d9a3766931b94e223db928a232f3769
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2018 Endless Mobile, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: Daniel Drake <drake@endlessm.com>
22 * gio-launch-desktop: GDesktopAppInfo helper
23 * Executable wrapper to set GIO_LAUNCHED_DESKTOP_FILE_PID
24 * There are complications when doing this in a fork()/exec() codepath,
25 * and it cannot otherwise be done with posix_spawn().
26 * This wrapper is designed to be minimal and lightweight.
27 * It does not even link against glib.
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <unistd.h>
35 int
36 main (int argc, char *argv[])
38 pid_t pid = getpid ();
39 char buf[50];
40 int r;
42 if (argc < 2)
43 return -1;
45 r = snprintf (buf, sizeof (buf), "GIO_LAUNCHED_DESKTOP_FILE_PID=%ld", (long) pid);
46 if (r >= sizeof (buf))
47 return -1;
49 putenv (buf);
51 return execvp (argv[1], argv + 1);