Skip to content

Commit

Permalink
Fixed return code check.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Apr 20, 2024
1 parent 9cb6d1e commit ca9de1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
11 changes: 7 additions & 4 deletions app/dmapi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ program dmapi
if (dm_is_error(rc)) call dm_stop(STOP_FAILURE)

! Run event loop.
do while (dm_fcgi_accept() /= E_NONE)
do while (dm_fcgi_accept() == E_NONE)
call dm_cgi_env(env)
call dm_cgi_router_dispatch(router, env, code)

Expand Down Expand Up @@ -1332,11 +1332,14 @@ subroutine route_root(env)

! Check database availability.
if (.not. dm_file_exists(db_beat)) then
rc = E_NOT_FOUND; message = 'beat database not found'
rc = E_NOT_FOUND
message = 'beat database not found'
else if (.not. dm_file_exists(db_log)) then
rc = E_NOT_FOUND; message = 'log database not found'
rc = E_NOT_FOUND
message = 'log database not found'
else if (.not. dm_file_exists(db_observ)) then
rc = E_NOT_FOUND; message = 'observation database not found'
rc = E_NOT_FOUND
message = 'observation database not found'
else
message = 'online'
end if
Expand Down
6 changes: 4 additions & 2 deletions src/dm_cgi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ integer function dm_cgi_content(env, content) result(rc)
rc = E_EMPTY
if (env%content_length == 0) return

rc = E_READ
nc = int(env%content_length, kind=c_size_t)
sz = c_read(STDIN_FILENO, c_loc(content), nc)
if (sz == 0) return

rc = E_EOF
if (sz == 0) return

rc = E_READ
if (sz /= nc) return

rc = E_NONE
end function dm_cgi_content

Expand Down
12 changes: 7 additions & 5 deletions src/dm_fcgi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,23 @@ integer function dm_fcgi_content(env, content) result(rc)
character(len=:), allocatable, intent(out) :: content !! Returned request body.

integer :: stat
integer(kind=i8) :: i
integer(kind=i8) :: i, n

n = env%content_length

fcgi_block: block
rc = E_EMPTY
if (env%content_length == 0) exit fcgi_block
if (n == 0) exit fcgi_block

rc = E_BOUNDS
if (env%content_length < 0) exit fcgi_block
if (n < 0) exit fcgi_block

rc = E_ALLOC
allocate (character(len=env%content_length) :: content, stat=stat)
allocate (character(len=n) :: content, stat=stat)
if (stat /= 0) exit fcgi_block

rc = E_NONE
do i = 1, env%content_length
do i = 1, n
content(i:i) = achar(fcgi_getchar())
end do

Expand Down

0 comments on commit ca9de1e

Please sign in to comment.