sleep.c revision 717603e391b52983ca1fd218e7333a1b9dfc5c05
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include "sd-id128.h"
#include "sd-messages.h"
#include "log.h"
#include "util.h"
#include "strv.h"
#include "fileio.h"
#include "build.h"
#include "sleep-config.h"
#include "def.h"
static int write_mode(char **modes) {
int r = 0;
char **mode;
int k;
if (k == 0)
return 0;
if (r == 0)
r = k;
}
if (r < 0)
strerror(-r));
return r;
}
char **state;
int r = 0;
int k;
k = write_string_stream(*f, *state);
if (k == 0)
return 0;
if (r == 0)
r = k;
fclose(*f);
if (!*f) {
return -errno;
}
}
return r;
}
char* arguments[4];
int r;
/* This file is opened first, so that if we hit an error,
* we can abort before modifying any state. */
if (!f) {
return -errno;
}
/* Configure the hibernation mode */
r = write_mode(modes);
if (r < 0)
return r;
"MESSAGE=Suspending system...",
note,
NULL);
r = write_state(&f, states);
if (r < 0)
return r;
"MESSAGE=System resumed.",
note,
NULL);
return r;
}
static int help(void) {
printf("%s COMMAND\n\n"
"Suspend the system, hibernate the system, or both.\n\n"
"Commands:\n"
" -h --help Show this help and exit\n"
" --version Print version string and exit\n"
" suspend Suspend the system\n"
" hibernate Hibernate the system\n"
" hybrid-sleep Both hibernate and suspend the system\n"
);
return 0;
}
enum {
ARG_VERSION = 0x100,
};
{}
};
int c;
switch(c) {
case 'h':
return help();
case ARG_VERSION:
return 0 /* done */;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
log_error("Usage: %s COMMAND",
return -EINVAL;
}
return -EINVAL;
}
return 1 /* work to do */;
}
int r;
log_open();
if (r <= 0)
goto finish;
if (r < 0)
goto finish;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}