Skip to content

Commit 5acfa80

Browse files
authored
Merge pull request #352 from darealshinji/appimagetool_master_patch1
Code clean-up
2 parents 4846ea9 + cc55137 commit 5acfa80

File tree

7 files changed

+92
-97
lines changed

7 files changed

+92
-97
lines changed

AppRun.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ int main(int argc, char *argv[])
5353
if (!appdir)
5454
die("Could not access /proc/self/exe\n");
5555

56-
char path[LINE_SIZE];
5756
int ret;
5857

5958
struct dirent **namelist;
@@ -74,7 +73,7 @@ int main(int argc, char *argv[])
7473
f = fopen(desktop_file, "r");
7574

7675
char *line = malloc(LINE_SIZE);
77-
unsigned int n = LINE_SIZE;
76+
size_t n = LINE_SIZE;
7877
int found = 0;
7978

8079
while (getline(&line, &n, f) != -1)

appimaged.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static GOptionEntry entries[] =
6868
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
6969
{ "install", 'i', 0, G_OPTION_ARG_NONE, &install, "Install this appimaged instance to $HOME", NULL },
7070
{ "uninstall", 'u', 0, G_OPTION_ARG_NONE, &uninstall, "Uninstall an appimaged instance from $HOME", NULL },
71-
{ "version", NULL, 0, G_OPTION_ARG_NONE, &version, "Show version number", NULL },
71+
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version number", NULL },
7272
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &remaining_args, NULL },
7373
{ NULL }
7474
};
@@ -153,11 +153,11 @@ void initially_register(const char *name, int level)
153153
}
154154
}
155155
}
156-
} while (entry = readdir(dir));
156+
} while ((entry = readdir(dir)) != NULL);
157157
closedir(dir);
158158
}
159159

160-
int add_dir_to_watch(char *directory)
160+
void add_dir_to_watch(char *directory)
161161
{
162162
if (g_file_test (directory, G_FILE_TEST_IS_DIR)){
163163
if(!inotifytools_watch_recursively(directory, WR_EVENTS) ) {
@@ -174,7 +174,7 @@ void handle_event(struct inotify_event *event)
174174
int ret;
175175
gchar *absolute_path = g_build_path(G_DIR_SEPARATOR_S, inotifytools_filename_from_wd(event->wd), event->name, NULL);
176176

177-
if(event->mask & IN_CLOSE_WRITE | event->mask & IN_MOVED_TO){
177+
if((event->mask & IN_CLOSE_WRITE) | (event->mask & IN_MOVED_TO)){
178178
if(g_file_test(absolute_path, G_FILE_TEST_IS_REGULAR)){
179179
pthread_t some_thread;
180180
struct arg_struct args;
@@ -188,7 +188,7 @@ void handle_event(struct inotify_event *event)
188188
}
189189
}
190190

191-
if(event->mask & IN_MOVED_FROM | event->mask & IN_DELETE){
191+
if((event->mask & IN_MOVED_FROM) | (event->mask & IN_DELETE)){
192192
pthread_t some_thread;
193193
struct arg_struct args;
194194
args.path = absolute_path;
@@ -237,7 +237,7 @@ int main(int argc, char ** argv) {
237237

238238
gchar *user_bin_dir = g_build_filename(g_get_home_dir(), "/.local/bin", NULL);
239239
gchar *installed_appimaged_location = g_build_filename(user_bin_dir, "appimaged", NULL);
240-
gchar *appimage_location = g_getenv("APPIMAGE");
240+
const gchar *appimage_location = g_getenv("APPIMAGE");
241241
gchar *own_desktop_file_location = g_build_filename(g_getenv("APPDIR"), "/appimaged.desktop", NULL);
242242
gchar *global_autostart_file = "/etc/xdg/autostart/appimaged.desktop";
243243
gchar *global_systemd_file = "/usr/lib/systemd/user/appimaged.service";
@@ -254,7 +254,7 @@ int main(int argc, char ** argv) {
254254
exit(0);
255255
}
256256

257-
if(install != NULL){
257+
if(install){
258258
if(((appimage_location != NULL)) && ((own_desktop_file_location != NULL))){
259259
printf("Running from within %s\n", appimage_location);
260260
if ( (! g_file_test ("/usr/bin/appimaged", G_FILE_TEST_EXISTS)) && (! g_file_test (global_autostart_file, G_FILE_TEST_EXISTS)) && (! g_file_test (global_systemd_file, G_FILE_TEST_EXISTS))){
@@ -297,7 +297,7 @@ int main(int argc, char ** argv) {
297297
if ( (! g_file_test ("/usr/bin/appimaged", G_FILE_TEST_EXISTS)) && ((! g_file_test (global_autostart_file, G_FILE_TEST_EXISTS)) || (! g_file_test (destination, G_FILE_TEST_EXISTS))) && (! g_file_test (global_systemd_file, G_FILE_TEST_EXISTS)) && (! g_file_test (installed_appimaged_location, G_FILE_TEST_EXISTS)) && (g_file_test (own_desktop_file_location, G_FILE_TEST_IS_REGULAR))){
298298
char *title;
299299
char *body;
300-
title = g_strdup_printf("Not installed\n", argv[0]);
300+
title = g_strdup_printf("Not installed\n");
301301
body = g_strdup_printf("Please run %s --install", argv[0]);
302302
notify(title, body, 15);
303303
exit(1);

appimagetool.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ident "AppImage by Simon Peter, http://appimage.org/"
2828

2929
#include <glib.h>
30+
#include <glib/gstdio.h>
3031
#include <stdlib.h>
3132

3233
#include <stdio.h>
@@ -41,9 +42,6 @@
4142
#include <sys/wait.h>
4243

4344
#include "binreloc.h"
44-
#ifndef NULL
45-
#define NULL ((void *) 0)
46-
#endif
4745

4846
#include <libgen.h>
4947

@@ -57,8 +55,6 @@ extern int _binary_runtime_start;
5755
extern int _binary_runtime_end;
5856

5957

60-
static gint repeats = 2;
61-
static gint max_size = 8;
6258
static gboolean list = FALSE;
6359
static gboolean verbose = FALSE;
6460
static gboolean version = FALSE;
@@ -107,7 +103,6 @@ int sfs_ls(char* image) {
107103
/* Generate a squashfs filesystem using mksquashfs on the $PATH
108104
* execlp(), execvp(), and execvpe() search on the $PATH */
109105
int sfs_mksquashfs(char *source, char *destination, int offset) {
110-
pid_t parent = getpid();
111106
pid_t pid = fork();
112107

113108
if (pid == -1) {
@@ -169,17 +164,16 @@ gchar* find_first_matching_file(const gchar *real_path, const gchar *pattern) {
169164
}
170165
}
171166
g_dir_close(dir);
172-
return NULL;
173167
}
174168
else {
175169
g_warning("%s: %s", real_path, g_strerror(errno));
176170
}
171+
return NULL;
177172
}
178173

179174
gchar* find_first_matching_file_nonrecursive(const gchar *real_path, const gchar *pattern) {
180175
GDir *dir;
181176
gchar *full_name;
182-
gchar *resulting;
183177
dir = g_dir_open(real_path, 0, NULL);
184178
if (dir != NULL) {
185179
const gchar *entry;
@@ -191,11 +185,11 @@ gchar* find_first_matching_file_nonrecursive(const gchar *real_path, const gchar
191185
}
192186
}
193187
g_dir_close(dir);
194-
return NULL;
195188
}
196189
else {
197190
g_warning("%s: %s", real_path, g_strerror(errno));
198191
}
192+
return NULL;
199193
}
200194

201195
gchar* get_desktop_entry(GKeyFile *kf, char *key) {
@@ -233,15 +227,14 @@ static void replacestr(char *line, const char *search, const char *replace)
233227

234228
static GOptionEntry entries[] =
235229
{
236-
// { "repeats", 'r', 0, G_OPTION_ARG_INT, &repeats, "Average over N repetitions", "N" },
237230
{ "list", 'l', 0, G_OPTION_ARG_NONE, &list, "List files in SOURCE AppImage", NULL },
238231
{ "updateinformation", 'u', 0, G_OPTION_ARG_STRING, &updateinformation, "Embed update information STRING; if zsyncmake is installed, generate zsync file", NULL },
239-
{ "bintray-user", NULL, 0, G_OPTION_ARG_STRING, &bintray_user, "Bintray user name", NULL },
240-
{ "bintray-repo", NULL, 0, G_OPTION_ARG_STRING, &bintray_repo, "Bintray repository", NULL },
241-
{ "version", NULL, 0, G_OPTION_ARG_NONE, &version, "Show version number", NULL },
232+
{ "bintray-user", 0, 0, G_OPTION_ARG_STRING, &bintray_user, "Bintray user name", NULL },
233+
{ "bintray-repo", 0, 0, G_OPTION_ARG_STRING, &bintray_repo, "Bintray repository", NULL },
234+
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version number", NULL },
242235
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Produce verbose output", NULL },
243236
{ "sign", 's', 0, G_OPTION_ARG_NONE, &sign, "Sign with gpg2", NULL },
244-
{ "comp", NULL, 0, G_OPTION_ARG_STRING, &sqfs_comp, "Squashfs compression", NULL },
237+
{ "comp", 0, 0, G_OPTION_ARG_STRING, &sqfs_comp, "Squashfs compression", NULL },
245238
{ "no-appstream", 'n', 0, G_OPTION_ARG_NONE, &no_appstream, "Do not check AppStream metadata", NULL },
246239
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &remaining_args, NULL },
247240
{ NULL }
@@ -579,7 +572,7 @@ main (int argc, char *argv[])
579572
}
580573
}
581574

582-
if(sign != NULL){
575+
if(sign){
583576
/* The user has indicated that he wants to sign */
584577
gchar *gpg2_path = g_find_program_in_path ("gpg2");
585578
gchar *sha256sum_path = g_find_program_in_path ("sha256sum");

build.sh

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# and builds AppImage
55
#
66

7+
CC="cc -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result"
8+
79
STATIC_BUILD=1
810
INSTALL_DEPENDENCIES=1
911

@@ -78,7 +80,7 @@ if [ $STATIC_BUILD -eq 1 ]; then
7880
cd openssl-1.1.0c
7981
mkdir -p build/lib
8082
./config --prefix=`pwd`/build
81-
make && make install
83+
make && make install PROCESS_PODS=''
8284
cd -
8385
rm openssl-1.1.0c/build/lib/*.so*
8486
fi
@@ -147,7 +149,7 @@ cp ../squashfs-tools/squashfs-tools/mksquashfs .
147149

148150
# Compile runtime but do not link
149151

150-
cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c ../runtime.c
152+
$CC -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -I../squashfuse/ -D_FILE_OFFSET_BITS=64 -g -Os -c ../runtime.c
151153

152154
# Prepare 1024 bytes of space for updateinformation
153155
printf '\0%.0s' {0..1023} > 1024_blank_bytes
@@ -160,7 +162,9 @@ objcopy --add-section .sha256_sig=1024_blank_bytes \
160162

161163
# Now statically link against libsquashfuse_ll, libsquashfuse and liblzma
162164
# and embed .upd_info and .sha256_sig sections
163-
cc ../elf.c ../notify.c ../getsection.c runtime3.o ../squashfuse/.libs/libsquashfuse_ll.a ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -L../xz-5.2.3/build/lib -Wl,-Bdynamic -lfuse -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl -o runtime
165+
$CC -o runtime ../elf.c ../notify.c ../getsection.c runtime3.o \
166+
../squashfuse/.libs/libsquashfuse_ll.a ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
167+
-L../xz-5.2.3/build/lib -Wl,-Bdynamic -lfuse -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -ldl
164168
strip runtime
165169

166170
# Test if we can read it back
@@ -195,15 +199,23 @@ ld -r -b binary -o data.o runtime
195199

196200
# Compile appimagetool but do not link - glib version
197201

198-
cc -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I../squashfuse/ $(pkg-config --cflags glib-2.0) -g -Os ../getsection.c -c ../appimagetool.c
202+
$CC -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" -D_FILE_OFFSET_BITS=64 -I../squashfuse/ \
203+
$(pkg-config --cflags glib-2.0) -g -Os ../getsection.c -c ../appimagetool.c
199204

200205
# Now statically link against libsquashfuse - glib version
201206
if [ $STATIC_BUILD -eq 1 ]; then
202207
# statically link against liblzma
203-
cc data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -L../xz-5.2.3/build/lib -Wl,-Bdynamic -lfuse -lpthread -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimagetool # liblz4
208+
$CC -o appimagetool data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c \
209+
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
210+
-L../xz-5.2.3/build/lib \
211+
-Wl,-Bdynamic -lfuse -lpthread \
212+
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
204213
else
205214
# dinamically link against distro provided liblzma
206-
cc data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -Wl,-Bdynamic -lfuse -lpthread -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -llzma -o appimagetool # liblz4
215+
$CC -o appimagetool data.o appimagetool.o ../elf.c ../getsection.c -DENABLE_BINRELOC ../binreloc.c \
216+
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
217+
-Wl,-Bdynamic -lfuse -lpthread \
218+
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -llzma
207219
fi
208220

209221
# Version without glib
@@ -213,25 +225,28 @@ fi
213225
# Compile and link digest tool
214226

215227
if [ $STATIC_BUILD -eq 1 ]; then
216-
cc -o digest ../getsection.c ../digest.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
228+
$CC -o digest ../getsection.c ../digest.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib \
229+
-Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lz -ldl
217230
else
218-
cc -o digest ../getsection.c ../digest.c -Wl,-Bdynamic -lssl -lcrypto -lz -ldl
231+
$CC -o digest ../getsection.c ../digest.c -Wl,-Bdynamic -lssl -lcrypto -lz -ldl
219232
fi
220233

221234
strip digest
222235

223236
# Compile and link validate tool
224237

225238
if [ $STATIC_BUILD -eq 1 ]; then
226-
cc -o validate ../getsection.c ../validate.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -ldl
239+
$CC -o validate ../getsection.c ../validate.c -I../openssl-1.1.0c/build/include -L../openssl-1.1.0c/build/lib \
240+
-Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -ldl
227241
else
228-
cc -o validate ../getsection.c ../validate.c -Wl,-Bdynamic -lssl -lcrypto -lglib-2.0 $(pkg-config --cflags glib-2.0) -lz -ldl
242+
$CC -o validate ../getsection.c ../validate.c -Wl,-Bdynamic -lssl -lcrypto \
243+
-Wl,--as-needed $(pkg-config --cflags --libs glib-2.0) -lz -ldl
229244
fi
230245

231246
strip validate
232247

233248
# AppRun
234-
cc ../AppRun.c -o AppRun
249+
$CC ../AppRun.c -o AppRun
235250

236251
# check for libarchive name
237252
have_libarchive3=0
@@ -244,9 +259,26 @@ rm -f a.out
244259

245260
# appimaged, an optional component
246261
if [ $STATIC_BUILD -eq 1 ]; then
247-
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -L../xz-5.2.3/build/lib -I../inotify-tools-3.14/build/include -L../inotify-tools-3.14/build/lib -Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags gio-2.0) $(pkg-config --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimaged # liblz4
262+
$CC -std=gnu99 -o appimaged -I../squashfuse/ ../getsection.c ../notify.c ../elf.c ../appimaged.c \
263+
-D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" \
264+
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
265+
-L../xz-5.2.3/build/lib -I../inotify-tools-3.14/build/include -L../inotify-tools-3.14/build/lib \
266+
-Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} \
267+
-Wl,--as-needed \
268+
$(pkg-config --cflags --libs glib-2.0) \
269+
$(pkg-config --cflags --libs gio-2.0) \
270+
$(pkg-config --cflags --libs cairo) \
271+
-ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic
248272
else
249-
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -Wl,-Bdynamic -linotifytools -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags gio-2.0) $(pkg-config --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -llzma -o appimaged # liblz4
273+
$CC -std=gnu99 -o appimaged -I../squashfuse/ ../getsection.c ../notify.c ../elf.c ../appimaged.c \
274+
-D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" \
275+
../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a \
276+
-Wl,-Bdynamic -linotifytools -larchive${archive_n} \
277+
-Wl,--as-needed \
278+
$(pkg-config --cflags --libs glib-2.0) \
279+
$(pkg-config --cflags --libs gio-2.0) \
280+
$(pkg-config --cflags --libs cairo) \
281+
-ldl -lpthread -lz -llzma
250282
fi
251283

252284
cd ..

digest.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ int sha256_file(char *path, char outputBuffer[65], int skip_offset, int skip_len
9292
return 0;
9393
}
9494

95-
int main(int argc,char **argv) {
95+
int main(int argc,char **argv)
96+
{
97+
int res = 0;
98+
9699
if(argc < 2){
97100
fprintf(stderr, "Usage: %s file offset length\n", argv[0]);
98101
fprintf(stderr, "If no offset and length are provided, the ELF section '%s' is skipped\n\n", segment_name);
@@ -124,8 +127,8 @@ int main(int argc,char **argv) {
124127
fprintf(stderr, "offset+length cannot be less than the file size\n");
125128
exit(1);
126129
}
127-
static unsigned char buffer[65];
128-
int res = sha256_file(filename, buffer, skip_offset, skip_length);
130+
static char buffer[65];
131+
res = sha256_file(filename, buffer, skip_offset, skip_length);
129132
printf("%s\n", buffer);
130133
return res;
131134
}

0 commit comments

Comments
 (0)