Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steamrt
steam-runtime-tools
Commits
47fafa97
Commit
47fafa97
authored
7 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
Port most code (except fdio) to new style
There's a lot more fdio code, starting with some of the easier ones.
parent
74383ba4
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
glnx-dirfd.c
+3
-9
3 additions, 9 deletions
glnx-dirfd.c
glnx-lockfile.c
+7
-16
7 additions, 16 deletions
glnx-lockfile.c
glnx-shutil.c
+21
-55
21 additions, 55 deletions
glnx-shutil.c
with
31 additions
and
80 deletions
glnx-dirfd.c
+
3
−
9
View file @
47fafa97
...
...
@@ -209,13 +209,12 @@ glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_iter,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
struct
dirent
*
ret_dent
;
g_return_val_if_fail
(
out_dent
,
FALSE
);
if
(
!
glnx_dirfd_iterator_next_dent
(
dfd_iter
,
out_dent
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
ret_dent
=
*
out_dent
;
...
...
@@ -226,17 +225,12 @@ glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_iter,
{
struct
stat
stbuf
;
if
(
TEMP_FAILURE_RETRY
(
fstatat
(
dfd_iter
->
fd
,
ret_dent
->
d_name
,
&
stbuf
,
AT_SYMLINK_NOFOLLOW
))
!=
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno
(
error
);
ret_dent
->
d_type
=
IFTODT
(
stbuf
.
st_mode
);
}
}
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
glnx-lockfile.c
+
7
−
16
View file @
47fafa97
...
...
@@ -61,7 +61,6 @@
*/
gboolean
glnx_make_lock_file
(
int
dfd
,
const
char
*
p
,
int
operation
,
GLnxLockFile
*
out_lock
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
glnx_fd_close
int
fd
=
-
1
;
g_autofree
char
*
t
=
NULL
;
int
r
;
...
...
@@ -89,10 +88,8 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc
struct
stat
st
;
fd
=
openat
(
dfd
,
p
,
O_CREAT
|
O_RDWR
|
O_NOFOLLOW
|
O_CLOEXEC
|
O_NOCTTY
,
0600
);
if
(
fd
<
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
if
(
fd
<
0
)
return
glnx_throw_errno
(
error
);
/* Unfortunately, new locks are not in RHEL 7.1 glibc */
#ifdef F_OFD_SETLK
...
...
@@ -107,10 +104,8 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc
if
(
errno
==
EINVAL
)
r
=
flock
(
fd
,
operation
);
if
(
r
<
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
if
(
r
<
0
)
return
glnx_throw_errno
(
error
);
}
/* If we acquired the lock, let's check if the file
...
...
@@ -120,10 +115,8 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc
* hence try again. */
r
=
fstat
(
fd
,
&
st
);
if
(
r
<
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
if
(
r
<
0
)
return
glnx_throw_errno
(
error
);
if
(
st
.
st_nlink
>
0
)
break
;
...
...
@@ -142,9 +135,7 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc
fd
=
-
1
;
t
=
NULL
;
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
void
glnx_release_lock_file
(
GLnxLockFile
*
f
)
{
...
...
This diff is collapsed.
Click to expand it.
glnx-shutil.c
+
21
−
55
View file @
47fafa97
...
...
@@ -31,14 +31,12 @@ glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
struct
dirent
*
dent
;
while
(
TRUE
)
{
if
(
!
glnx_dirfd_iterator_next_dent_ensure_dtype
(
dfd_iter
,
&
dent
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
if
(
dent
==
NULL
)
break
;
...
...
@@ -48,33 +46,25 @@ glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter,
if
(
!
glnx_dirfd_iterator_init_at
(
dfd_iter
->
fd
,
dent
->
d_name
,
FALSE
,
&
child_dfd_iter
,
error
))
goto
out
;
return
FALSE
;
if
(
!
glnx_shutil_rm_rf_children
(
&
child_dfd_iter
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
if
(
unlinkat
(
dfd_iter
->
fd
,
dent
->
d_name
,
AT_REMOVEDIR
)
==
-
1
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno_prefix
(
error
,
"unlinkat"
);
}
else
{
if
(
unlinkat
(
dfd_iter
->
fd
,
dent
->
d_name
,
0
)
==
-
1
)
{
if
(
errno
!=
ENOENT
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno_prefix
(
error
,
"unlinkat"
);
}
}
}
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
/**
...
...
@@ -94,7 +84,6 @@ glnx_shutil_rm_rf_at (int dfd,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
glnx_fd_close
int
target_dfd
=
-
1
;
g_auto
(
GLnxDirFdIterator
)
dfd_iter
=
{
0
,
};
...
...
@@ -114,40 +103,28 @@ glnx_shutil_rm_rf_at (int dfd,
else
if
(
errsv
==
ENOTDIR
||
errsv
==
ELOOP
)
{
if
(
unlinkat
(
dfd
,
path
,
0
)
!=
0
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno_prefix
(
error
,
"unlinkat"
);
}
else
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno_prefix
(
error
,
"open(%s)"
,
path
);
}
else
{
if
(
!
glnx_dirfd_iterator_init_take_fd
(
target_dfd
,
&
dfd_iter
,
error
))
goto
out
;
return
FALSE
;
target_dfd
=
-
1
;
if
(
!
glnx_shutil_rm_rf_children
(
&
dfd_iter
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
if
(
unlinkat
(
dfd
,
path
,
AT_REMOVEDIR
)
==
-
1
)
{
int
errsv
=
errno
;
if
(
errsv
!=
ENOENT
)
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
if
(
errno
!=
ENOENT
)
return
glnx_throw_errno_prefix
(
error
,
"unlinkat"
);
}
}
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
static
gboolean
...
...
@@ -157,11 +134,10 @@ mkdir_p_at_internal (int dfd,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
gboolean
did_recurse
=
FALSE
;
if
(
g_cancellable_set_error_if_cancelled
(
cancellable
,
error
))
goto
out
;
return
FALSE
;
again:
if
(
mkdirat
(
dfd
,
path
,
mode
)
==
-
1
)
...
...
@@ -179,7 +155,7 @@ mkdir_p_at_internal (int dfd,
if
(
!
glnx_shutil_mkdir_p_at
(
dfd
,
path
,
mode
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
/* Now restore it for another mkdir attempt */
*
lastslash
=
'/'
;
...
...
@@ -194,15 +170,10 @@ mkdir_p_at_internal (int dfd,
*/
}
else
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
return
glnx_throw_errno_prefix
(
error
,
"mkdir(%s)"
,
path
);
}
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
/**
...
...
@@ -223,28 +194,23 @@ glnx_shutil_mkdir_p_at (int dfd,
GCancellable
*
cancellable
,
GError
**
error
)
{
gboolean
ret
=
FALSE
;
struct
stat
stbuf
;
char
*
buf
;
/* Fast path stat to see whether it already exists */
if
(
fstatat
(
dfd
,
path
,
&
stbuf
,
AT_SYMLINK_NOFOLLOW
)
==
0
)
{
/* Note early return */
if
(
S_ISDIR
(
stbuf
.
st_mode
))
{
ret
=
TRUE
;
goto
out
;
}
return
TRUE
;
}
buf
=
strdupa
(
path
);
if
(
!
mkdir_p_at_internal
(
dfd
,
buf
,
mode
,
cancellable
,
error
))
goto
out
;
return
FALSE
;
ret
=
TRUE
;
out:
return
ret
;
return
TRUE
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment