File: s2ram-main.c

package info (click to toggle)
uswsusp 1.0+20120915-6.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,572 kB
  • sloc: ansic: 7,164; sh: 566; makefile: 223; perl: 65
file content (129 lines) | stat: -rw-r--r-- 2,583 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Suspend-to-RAM
 *
 * Copyright 2006 Pavel Machek <pavel@suse.cz>
 * Copyright 2009 Rodolfo Garcia <kix@kix.es>
 * Copyright 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
 * Distribute under GPLv2.
 */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <string.h>

#ifndef S2RAM
#define S2RAM
#endif
#include "whitelist.h"
#include "s2ram.h"
#include "config_parser.h"


int main(int argc, char *argv[])
{
	int i, ret = 0;
	struct option options[] = {
		{
			"help\0\tthis text.",
			no_argument,	NULL, 'h'
		},
		{
			"version\0\t\t\tversion information",
			no_argument,	NULL, 'V'
		},
		{
			"test\0\ttest if the machine is in the database.",
			no_argument,	NULL, 'n'
		},
		{
			"kmstest\0\ttest if the kernel has KMS support.",
			no_argument,	NULL, 'K'
		},
		{
			"identify\0prints a string that identifies the machine.",
			no_argument,	NULL, 'i'
		},
		HACKS_LONG_OPTS
		{	NULL, 0,	NULL, 0	}
	};
	const char *optstring = "hVnKi" "fspmrva:k";

	while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
		switch (i) {
		case 'h':
			usage("s2ram", options, optstring);
			exit(0);
		case 'V':
			version("s2ram", whitelist_version);
			exit(EXIT_SUCCESS);
		case 'i':
			identify_machine();
			exit(0);
		case 'n':
			ret = machine_known();
			exit(ret);
		case 'K':
			ret = s2ram_check_kms();
			if (!ret)
				printf("This kernel has KMS support.\n");
			else
				printf("This kernel doesn't have KMS support.\n");
			exit(ret);
		case '?':
			usage("s2ram", options, optstring);
			exit(1);
			break;
		default:
			s2ram_add_flag(i, optarg);
			break;
		}
	}

	/* Test if s2ram will use quirks from the configuration file */
	ret = get_s2ram_config();

	/* Check if the KMS support is disabled by user */
	if (!no_kms_flag) {
		/* KMS */
		ret = s2ram_check_kms();
		if (!ret) {
			printf("KMS graphics driver is in use, skipping quirks.\n");
			return s2ram_generic_do();
		} else {
			printf("This kernel doesn't have KMS support.\n");
		}
	} else {
		printf("KMS disabled by user.\n");
	}

	if (ret) {
		/* No configuration file, using quirks form database */
		ret = s2ram_is_supported();

		if (ret == S2RAM_UNKNOWN) {
			printf("Machine is unknown.\n");
			identify_machine();
			goto out;
		}

		if (ret == S2RAM_NOFB)
			printf("This machine can only suspend without framebuffer.\n");

		if (ret)
			goto out;
	} else {
		printf("Using quirks from the configuration file.\n");
	}

	ret = s2ram_hacks();
	if (ret)
		goto out;
	ret = s2ram_do();
	s2ram_resume();

 out:
	return ret;
}