~siretart/gxine/bug.542506

« back to all changes in this revision

Viewing changes to src/client.c

  • Committer: Bazaar Package Importer
  • Author(s): Siggi Langauf
  • Date: 2005-01-05 01:49:18 UTC
  • mto: (2.1.1 etch) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050105014918-wgldiqcd79ck2b0v
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
#include "i18n.h"
1
3
 
2
4
#include <stdio.h>
3
5
#include <stdlib.h>
7
9
#include <sys/un.h>
8
10
#include <string.h>
9
11
#include <fcntl.h>
 
12
#include <signal.h>
10
13
 
11
14
#define SOCKET_FILENAME "%s/.gxine/socket"
12
15
#define BUF_LEN 1024
13
16
 
 
17
static volatile int done = 0;
 
18
 
 
19
static void sigpipe (int sig)
 
20
{
 
21
  done = 1;
 
22
  signal (SIGPIPE, sigpipe);
 
23
}
 
24
 
14
25
int main (int argc, char **argv) {
15
26
 
16
27
  int                fd;
18
29
  int                length = sizeof(struct sockaddr_un);
19
30
  char               filename [1024];
20
31
  char              *tstr;
 
32
  int                ret = 0;
 
33
 
 
34
  signal (SIGPIPE, sigpipe);
21
35
 
22
36
  /* server filename */
23
37
  snprintf (filename, 1024, SOCKET_FILENAME, getenv ("HOME")); 
24
38
 
25
 
  printf ("connecting to %s...\n", filename);
 
39
  printf (_("Connecting to %s...\n"), filename);
26
40
 
27
41
  fd = socket (AF_UNIX, SOCK_STREAM, 0);
28
42
 
50
64
    exit (EXIT_FAILURE);
51
65
  }
52
66
  
53
 
  printf ("connected.\n");
 
67
  printf (_("Connected.\n"));
54
68
 
55
69
  if (argc>1) {
56
70
 
57
71
    /* noninteractive */
58
72
 
59
 
    printf ("sending command\n");
 
73
    printf (_("Sending command\n"));
60
74
 
61
75
    write (fd, argv[1], strlen(argv[1]));
62
76
    write (fd, "\n", 1);
63
77
 
64
 
    printf ("done.\n");
 
78
    printf (_("Done.\n"));
65
79
 
66
80
  } else {
67
81
    /* interactive mode */
72
86
    else
73
87
      n=STDIN_FILENO+1;
74
88
 
75
 
    while (1) {
 
89
    while (!done) {
76
90
 
77
91
      char buf[10];
78
92
      fd_set rset;
83
97
 
84
98
      if (select (n, &rset, NULL, NULL, NULL) <= 0) {
85
99
        perror ("client: select: ");
86
 
        return -1;
 
100
        ret = 2;
 
101
        break;
87
102
      }
88
103
 
89
104
      if (FD_ISSET (fd, &rset)) {
102
117
 
103
118
  unlink (tstr);
104
119
 
105
 
  return 0;
 
120
  return ret;
106
121
}