~ted/ubuntu-app-launch/install-root

« back to all changes in this revision

Viewing changes to snappy-xmir-envvars.c

  • Committer: Ted Gould
  • Date: 2016-12-01 23:34:45 UTC
  • Revision ID: ted@gould.cx-20161201233445-4c7bgl4gz08qrs2q
Switch to an abstract socket

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <stdlib.h>
25
25
#include <sys/types.h>
26
26
#include <sys/socket.h>
 
27
#include <sys/un.h>
27
28
#include <sys/wait.h>
28
29
#include <signal.h>
29
30
#include <string.h>
65
66
{
66
67
        /* Grab socket */
67
68
        if (argc != 2) {
68
 
                fprintf(stderr, "Usage: %s <fd>\n", argv[0]);
69
 
                return(EXIT_FAILURE);
70
 
        }
71
 
 
72
 
        int socketnum = atoi(argv[1]);
73
 
        if (!(socketnum > 0 && socketnum < 20)) {
74
 
                fprintf(stderr, "Passed socket ID not within a valid range: %d\n", socketnum);
75
 
                return(EXIT_FAILURE);
 
69
                fprintf(stderr, "Usage: %s <socket name>\n", argv[0]);
 
70
                return(EXIT_FAILURE);
 
71
        }
 
72
 
 
73
        char * socketname = argv[1];
 
74
 
 
75
        int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
 
76
        if (socketfd <= 0) {
 
77
                fprintf(stderr, "Unable to create socket");
 
78
                return EXIT_FAILURE;
 
79
        }
 
80
 
 
81
        struct sockaddr_un socketaddr = {0};
 
82
        socketaddr.sun_family = AF_UNIX;
 
83
        strcpy(socketaddr.sun_path, socketname);
 
84
        socketaddr.sun_path[0] = 0;
 
85
 
 
86
        if (connect(socketfd, (const struct sockaddr *)&socketaddr, sizeof(struct sockaddr_un)) < 0) {
 
87
                fprintf(stderr, "Unable to connect socket");
 
88
                return EXIT_FAILURE;
76
89
        }
77
90
 
78
91
        /* Dump envvars to socket */
79
 
        copyenv(socketnum, "DISPLAY");
80
 
        copyenv(socketnum, "DBUS_SESSION_BUS_ADDRESS");
 
92
        copyenv(socketfd, "DISPLAY");
 
93
        copyenv(socketfd, "DBUS_SESSION_BUS_ADDRESS");
81
94
 
82
95
        /* Close the socket */
83
 
        close(socketnum);
 
96
        close(socketfd);
84
97
 
85
98
        /* Wait for sigterm */
86
99
        signal(SIGTERM, termhandler);