2
#include "../../libpower/powersave_daemonlib.h"
3
#include <sys/socket.h>
8
int open_client_connection(void);
10
int main(int *argc, char *argv[]) {
11
// check whether there is a cmdline argument
12
if (argv[1] == NULL ) {
13
cerr << "You didn't provide any string which can be sent to the daemon\n";
17
// open a connection to the daemon
18
int fd = open_client_connection();
20
cerr << "Error opening connection to daemon\n";
24
int send = POWERSAVED_EVENT_RETURN;
25
// write the EVENT_RETURN integer to the daemon
26
int i = write(fd, &send, sizeof(send));
28
cerr << "Powersaved didn't accept event return\n";
32
// prepare the string to send
33
char * sendstr = argv[1];
34
//sendstr[strlen(sendstr)] = '\n'; // no longer, we now send 0-terminated strings.
36
// write the string to the daemon
37
int r = write(fd,sendstr, strlen(sendstr) + 1);
39
cerr << "Error writing string to daemon\n";
42
// wheter the daemon accepted the string doesn't matter, so close
49
// opens a socket to connect to daemon
50
int open_client_connection(void){
51
struct sockaddr_un address;
56
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
62
address.sun_family = AF_UNIX;
63
strcpy(address.sun_path, POWERSAVED_SOCKET_PATH);
65
result = connect(sockfd, (struct sockaddr*)&address, sizeof(address));