summaryrefslogtreecommitdiff
authorkejun.gao <kejun.gao@amlogic.com>2012-09-27 09:42:25 (GMT)
committer tao.dong@amlogic.com <tao.dong@droid03-sz.(none)>2012-10-23 08:33:14 (GMT)
commitb6ed6215982db04243cbc31cdecdf47a2ea45b7c (patch)
treea187d32dc353e523689c00559dae8cd1849c104e
parentef1b48bf3a04957fff741d170439c52ae750b81d (diff)
downloadpppoe-b6ed6215982db04243cbc31cdecdf47a2ea45b7c.zip
pppoe-b6ed6215982db04243cbc31cdecdf47a2ea45b7c.tar.gz
pppoe-b6ed6215982db04243cbc31cdecdf47a2ea45b7c.tar.bz2
1. Before exit, create file /etc/ppp/useraskquit to notify pppd.
2. Lock the file so that only one instance of pppoe runs on an interface
Diffstat
-rwxr-xr-xjni/src/common.c1
-rwxr-xr-xjni/src/discovery.c8
-rwxr-xr-xjni/src/pppoe.c68
3 files changed, 63 insertions, 14 deletions
diff --git a/jni/src/common.c b/jni/src/common.c
index 36f644a..6e63d3a 100755
--- a/jni/src/common.c
+++ b/jni/src/common.c
@@ -253,7 +253,6 @@ dropPrivs(void)
void
printErr(char const *str)
{
- fprintf(stderr, "pppoe: %s\n", str);
syslog(LOG_ERR, "%s", str);
}
diff --git a/jni/src/discovery.c b/jni/src/discovery.c
index 63884bc..3ec3b4b 100755
--- a/jni/src/discovery.c
+++ b/jni/src/discovery.c
@@ -662,7 +662,7 @@ discovery(PPPoEConnection *conn)
int padrAttempts = 0;
int timeout = conn->discoveryTimeout;
- fprintf(stderr, "discovery: timeout = %d\n", timeout);
+ syslog( LOG_INFO, "discovery: timeout = %d\n", timeout);
/* Skip discovery? */
if (conn->skipDiscovery) {
@@ -682,19 +682,16 @@ discovery(PPPoEConnection *conn)
timeout = conn->discoveryTimeout;
printErr("Timeout waiting for PADO packets");
} else {
- rp_fatal("Timeout waiting for PADO packets");
+ rp_fatal("FATAL: Timeout waiting for PADO packets");
}
}
- fprintf(stderr, "sendPADI\n");
syslog( LOG_INFO, "sendPADI\n");
sendPADI(conn);
conn->discoveryState = STATE_SENT_PADI;
gettimeofday(&current_time, NULL);
- fprintf(stderr, "before: sec = %d, usec = %d\n", (int)current_time.tv_sec, (int)current_time.tv_usec);
waitForPADO(conn, timeout);
gettimeofday(&current_time, NULL);
- fprintf(stderr, "after: sec = %d, usec = %d\n", (int)current_time.tv_sec, (int)current_time.tv_usec);
/* If we're just probing for access concentrators, don't do
exponential backoff. This reduces the time for an unsuccessful
probe to 15 seconds. */
@@ -723,7 +720,6 @@ discovery(PPPoEConnection *conn)
rp_fatal("Timeout waiting for PADS packets");
}
}
- fprintf(stderr, "sendPADR\n");
syslog( LOG_INFO, "sendPADR\n");
sendPADR(conn);
conn->discoveryState = STATE_SENT_PADR;
diff --git a/jni/src/pppoe.c b/jni/src/pppoe.c
index 6ad8293..5ebc59e 100755
--- a/jni/src/pppoe.c
+++ b/jni/src/pppoe.c
@@ -57,6 +57,7 @@ static char const RCSID[] =
#include <linux/termios.h>
#endif
#endif
+#include "pppoe_status.h"
/* Default interface if no -I option given */
#define DEFAULT_IF "eth0"
@@ -288,6 +289,7 @@ session(PPPoEConnection *conn)
syslog(LOG_ERR, "Inactivity timeout... something wicked happened on session %d",
(int) ntohs(conn->session));
sendPADT(conn, "RP-PPPoE: Inactivity timeout");
+ syslog(LOG_ERR, "EXIT");
exit(EXIT_FAILURE);
}
@@ -343,6 +345,35 @@ sigPADT(int src)
//exit(EXIT_SUCCESS);
}
+
+
+static void
+sigUserAskExit(int src)
+{
+ int prop_val[64];
+ FILE *file;
+ syslog(LOG_INFO,"Received signal %d on session %d.",
+ (int)src, (int) ntohs(Connection->session));
+
+ /*
+ syslog(LOG_INFO,"set net.ppp.usreit as yes");
+ property_set("net.ppp.usreit", "yes");
+ property_get("net.ppp.usreit", prop_val, "unknown");
+ syslog(LOG_INFO,"read net.ppp.usreit %s", prop_val);
+ */
+ umask(0);
+ file = fopen(_ROOT_PATH "/etc/ppp/useraskquit", "w");
+ if (!file) {
+ syslog(LOG_INFO, "Could not open %s: %s\n",
+ "/etc/ppp/useraskquit", strerror(errno));
+ }
+ else
+ fclose(file);
+
+ sendPADTf(Connection, "RP-PPPoE: Received signal %d", src);
+}
+
+
/**********************************************************************
*%FUNCTION: usage
*%ARGUMENTS:
@@ -391,6 +422,9 @@ usage(char const *argv0)
exit(EXIT_SUCCESS);
}
+static char *lockfile_path;
+#define LOCKFILE_FORMAT _ROOT_PATH "/etc/ppp/pppoe-%s.lock"
+
/**********************************************************************
*%FUNCTION: main
*%ARGUMENTS:
@@ -408,6 +442,8 @@ main(int argc, char *argv[])
unsigned int m[6]; /* MAC address in -e option */
unsigned int s; /* Temporary to hold session */
FILE *pidfile;
+ int pidfd = -1;
+ int len;
unsigned int discoveryType, sessionType;
char const *options;
@@ -510,12 +546,7 @@ main(int argc, char *argv[])
case 'p':
switchToRealID();
pidfile = fopen(optarg, "w");
- if (pidfile) {
- syslog( LOG_INFO, "open %s OK\n", optarg);
- fprintf(pidfile, "%lu\n", (unsigned long) getpid());
- fclose(pidfile);
- }
- else {
+ if (!pidfile) {
syslog( LOG_INFO, "Could not open %s: %s\n",
optarg, strerror(errno));
}
@@ -591,6 +622,29 @@ main(int argc, char *argv[])
#endif
}
+ len = strlen(LOCKFILE_FORMAT) + strlen(conn.ifName) + 2;
+ lockfile_path = malloc(len);
+ snprintf(lockfile_path, len, LOCKFILE_FORMAT, conn.ifName);
+
+ pidfd = open(lockfile_path, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
+ if (pidfd == -1) {
+ syslog(LOG_ERR, "failed to open %s. EXIT", lockfile_path);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Lock the file so that only one instance of pppoe runs
+ * on an interface */
+ if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
+ syslog(LOG_ERR, "failed to lock %s. EXIT", lockfile_path);
+ exit(EXIT_FAILURE);
+ }
+
+ if (pidfile) {
+ syslog( LOG_INFO, "open %s OK\n", optarg);
+ fprintf(pidfile, "%lu\n", (unsigned long) getpid());
+ fclose(pidfile);
+ }
+
if (!conn.printACNames) {
#ifdef HAVE_N_HDLC
@@ -664,7 +718,7 @@ main(int argc, char *argv[])
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGHUP, sigPADT);
- signal(SIGUSR1, sigPADT);
+ signal(SIGUSR1, sigUserAskExit);
session(&conn);
return 0;