Deleted Added
full compact
pen.c (96388) pen.c (96392)
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * Routines for managing the "play pen".
18 *
19 */
20
21#include <sys/cdefs.h>
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * Routines for managing the "play pen".
18 *
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/pen.c 96388 2002-05-11 03:48:49Z alfred $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/pen.c 96392 2002-05-11 04:17:55Z alfred $");
23
24#include "lib.h"
25#include <err.h>
26#include <libgen.h>
27#include <sys/signal.h>
28#include <sys/param.h>
29#include <sys/mount.h>
30

--- 26 unchanged lines hidden (view full) ---

57 strcpy(pen, "/tmp/instmp.XXXXXX");
58 else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
59 strcpy(pen, "/usr/tmp/instmp.XXXXXX");
60 else {
61 cleanup(0);
62 errx(2,
63"%s: can't find enough temporary space to extract the files, please set your\n"
64"PKG_TMPDIR environment variable to a location with at least %ld bytes\n"
23
24#include "lib.h"
25#include <err.h>
26#include <libgen.h>
27#include <sys/signal.h>
28#include <sys/param.h>
29#include <sys/mount.h>
30

--- 26 unchanged lines hidden (view full) ---

57 strcpy(pen, "/tmp/instmp.XXXXXX");
58 else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
59 strcpy(pen, "/usr/tmp/instmp.XXXXXX");
60 else {
61 cleanup(0);
62 errx(2,
63"%s: can't find enough temporary space to extract the files, please set your\n"
64"PKG_TMPDIR environment variable to a location with at least %ld bytes\n"
65"free", __FUNCTION__, (long)sz);
65"free", __func__, (long)sz);
66 return NULL;
67 }
68 return pen;
69}
70
71#define MAX_STACK 20
72static char *pstack[MAX_STACK];
73static int pdepth = -1;
74
75static void
76pushPen(const char *pen)
77{
78 if (++pdepth == MAX_STACK)
66 return NULL;
67 }
68 return pen;
69}
70
71#define MAX_STACK 20
72static char *pstack[MAX_STACK];
73static int pdepth = -1;
74
75static void
76pushPen(const char *pen)
77{
78 if (++pdepth == MAX_STACK)
79 errx(2, "%s: stack overflow.\n", __FUNCTION__);
79 errx(2, "%s: stack overflow.\n", __func__);
80 pstack[pdepth] = strdup(pen);
81}
82
83static void
84popPen(char *pen)
85{
86 if (pdepth == -1) {
87 pen[0] = '\0';

--- 10 unchanged lines hidden (view full) ---

98char *
99make_playpen(char *pen, off_t sz)
100{
101 if (!find_play_pen(pen, sz))
102 return NULL;
103
104 if (!mkdtemp(pen)) {
105 cleanup(0);
80 pstack[pdepth] = strdup(pen);
81}
82
83static void
84popPen(char *pen)
85{
86 if (pdepth == -1) {
87 pen[0] = '\0';

--- 10 unchanged lines hidden (view full) ---

98char *
99make_playpen(char *pen, off_t sz)
100{
101 if (!find_play_pen(pen, sz))
102 return NULL;
103
104 if (!mkdtemp(pen)) {
105 cleanup(0);
106 errx(2, "%s: can't mktemp '%s'", __FUNCTION__, pen);
106 errx(2, "%s: can't mktemp '%s'", __func__, pen);
107 }
108 if (chmod(pen, 0700) == FAIL) {
109 cleanup(0);
107 }
108 if (chmod(pen, 0700) == FAIL) {
109 cleanup(0);
110 errx(2, "%s: can't mkdir '%s'", __FUNCTION__, pen);
110 errx(2, "%s: can't mkdir '%s'", __func__, pen);
111 }
112
113 if (Verbose) {
114 if (sz)
115 fprintf(stderr, "Requested space: %d bytes, free space: %qd bytes in %s\n", (int)sz, (long long)min_free(pen), pen);
116 }
117
118 if (min_free(pen) < sz) {
119 rmdir(pen);
120 cleanup(0);
121 errx(2, "%s: not enough free space to create '%s'.\n"
122 "Please set your PKG_TMPDIR environment variable to a location\n"
111 }
112
113 if (Verbose) {
114 if (sz)
115 fprintf(stderr, "Requested space: %d bytes, free space: %qd bytes in %s\n", (int)sz, (long long)min_free(pen), pen);
116 }
117
118 if (min_free(pen) < sz) {
119 rmdir(pen);
120 cleanup(0);
121 errx(2, "%s: not enough free space to create '%s'.\n"
122 "Please set your PKG_TMPDIR environment variable to a location\n"
123 "with more space and\ntry the command again", __FUNCTION__, pen);
123 "with more space and\ntry the command again", __func__, pen);
124 }
125
126 if (!getcwd(Previous, FILENAME_MAX)) {
127 upchuck("getcwd");
128 return NULL;
129 }
130
131 if (chdir(pen) == FAIL) {
132 cleanup(0);
124 }
125
126 if (!getcwd(Previous, FILENAME_MAX)) {
127 upchuck("getcwd");
128 return NULL;
129 }
130
131 if (chdir(pen) == FAIL) {
132 cleanup(0);
133 errx(2, "%s: can't chdir to '%s'", __FUNCTION__, pen);
133 errx(2, "%s: can't chdir to '%s'", __func__, pen);
134 }
135
136 if (PenLocation[0])
137 pushPen(PenLocation);
138
139 strcpy(PenLocation, pen);
140 return Previous;
141}

--- 4 unchanged lines hidden (view full) ---

146{
147 void (*oldsig)(int);
148
149 /* Don't interrupt while we're cleaning up */
150 oldsig = signal(SIGINT, SIG_IGN);
151 if (Previous[0]) {
152 if (chdir(Previous) == FAIL) {
153 cleanup(0);
134 }
135
136 if (PenLocation[0])
137 pushPen(PenLocation);
138
139 strcpy(PenLocation, pen);
140 return Previous;
141}

--- 4 unchanged lines hidden (view full) ---

146{
147 void (*oldsig)(int);
148
149 /* Don't interrupt while we're cleaning up */
150 oldsig = signal(SIGINT, SIG_IGN);
151 if (Previous[0]) {
152 if (chdir(Previous) == FAIL) {
153 cleanup(0);
154 errx(2, "%s: can't chdir back to '%s'", __FUNCTION__, Previous);
154 errx(2, "%s: can't chdir back to '%s'", __func__, Previous);
155 }
156 Previous[0] = '\0';
157 }
158 if (PenLocation[0]) {
159 if (PenLocation[0] == '/' && vsystem("rm -rf %s", PenLocation))
160 warnx("couldn't remove temporary dir '%s'", PenLocation);
161 popPen(PenLocation);
162 }

--- 14 unchanged lines hidden ---
155 }
156 Previous[0] = '\0';
157 }
158 if (PenLocation[0]) {
159 if (PenLocation[0] == '/' && vsystem("rm -rf %s", PenLocation))
160 warnx("couldn't remove temporary dir '%s'", PenLocation);
161 popPen(PenLocation);
162 }

--- 14 unchanged lines hidden ---